typo3 extbase: show section only on certain pages - php

On a page and all of its subpages, I want to include a certain section. In my default template I added this:
<div class="container">
<f:render section="Productsearch"/>
</div>
But I want this section to only be included on certain pages. How can I achieve this?

Use a different layout on these pages. You can probably do this by using a setting (plugins.tx_yourext.settings.layoutName = Layout2.html), and then using that in the template:
<f:layout name="{settings.layoutName}"/>
The layout on the special pages renders the section, the usual layout does not render it.
EDIT: You could also just use a condition in the layout. Set plugins.tx_yourext.settings.showProductSearch = 1 (or 0) on the pages, preferrably using a TypoScript constant. Then use it in a condition:
<f:if condition="{settings.showProductSearch}">
<f:render section="Productsearch"/>
</f:if>

Related

OCtoberCMS Blog plugin Rainlab

When i create a new Post and write in the excerpt, the post image on the news page just dissappears . It only works if i have no excerpt. Also .. How can i create new posts with existing classes already written in my css?
Without the excerpt ir works just fine. Showing image and text that i add on the post.
My code
<section id="content">
<div class="content-wrap">
<div class="container clearfix">
<div class="row"> {% component 'blogPosts' %}
</div>
</div>
</div>
</section><!-- #content end -->
When not defining an excerpt, a summary attribute is appended to the model. See https://github.com/rainlab/blog-plugin/blob/master/models/Post.php#L344 . If your content starts with an image, it might be that the summary function kicks in and generates the image.
As for the CSS part
I think you're looking to override the partial set by {% componenent 'blogPosts' %}. As per the docs (https://octobercms.com/docs/cms/components#overriding-partials)
All component partials can be overridden using the theme partials. If
a component called channel uses the title.htm partial. We can override
the partial by creating a file in our theme called
partials/channel/title.htm.
Alternatively you can cmd / ctrl + doubleclick to expand the default component markup inside the CMS editor.
In this way you can edit your markup to match your theme.
If you want to override markup there is really easy way. for image #CptMeatball added proper answer you can check that out.
This way you have full control on mark-up and you can edit it.
1. Click on expand component it will reveal mark-up of component
2. Now you can add your own markup and edit it.
if any doubt please comment.

What have suppose to using laravel yield() function?

main page -> welcome.blade.php
#extends('layouts.footer_back_to_top')
#section('footer_back_to_top')
#endsection()
footer page -> footer_back_to_top.blade.php
<p id="back-top">
<span></span> Back to Top
</p>
#yield('footer_back_to_top')
The question I want to ask is without using #yield('footer_back_to_top') still will display the result?
No, result won't be displayed. You should use #yield to make this section displayed and in child view you normally define #section where you define what should be displayed.

Can I have a Laravel 4.2 blade include with it's own controller?

I have a sidebar include file that is present on every page of the website I am working on.
layout.blade:
<div class="after-login buying-process-wrapper">
<!--page content-->
{{ $content }}
<!-- end of page content-->
<!-- Sidebar -->
#include('layout.sidebar')
<!-- End of Sidebar -->
</div>
My controller sets $layout and renders the above blade file, but layout.sidebar is an include file which requires PHP to populate it's content.
Can I set a controller/route for this sidebar alone (and how would I do it?), or am I forced to have to duplicate the same calls to the function that handles the sidebar content in every controller?
I'm trying to find a better solution than having to go in to every controller and calling ->sidebar() every time each page is loaded.
Thanks
Why are you still using Laravel 4.2? It't 5.7 now and I strongly recommend you to upgrade to the latest version.
Answer to your question:
No, you don't need to call functions that handle your sidebar contents in every controller. You can share you common data across all or some of your views by using View Composer.
From Laravel 4.2 Documentation:
View composers are callbacks or class methods that are called when a view is rendered. If you have data that you want bound to a given view each time that view is rendered throughout your application, a view composer can organize that code into a single location. Therefore, view composers may function like "view models" or "presenters".
If you are using newer versions of Laravel, remember to switch to the right documentation from the right upper corner.
Also, when using Blade #include directive, you can optionally pass variables into the "included" components:
#include('layout.sidebar', ['my_var' => 'value goes here'])
And you can use {{ $my_var }} in your component just like you normally would in your blade templates.

Show a view in a layout without including other files in the view in AiryMVC framework?

If the view contains a header and footer, every view needs to include both in order to show properly.
For example, all my views have
include header.php
<div class="main">
... put the view here
</div>
include footer.php
Can we define a layout or template in AiryMVC so each view does not include header and footer but still shows the header and footer in the page?
You should define layout that contains the view in the controller. Then, instead of using
$this->view->render();
You need to use
$this->layout->render();
in the controller.

Drupal 7 inject div into existing structure

I am using drupal 7
views-view--myview.tpl.php sample code
<?php if ($rows): ?>
<?php print $rows; ?>
When i see this in firebug i see the structure
<div class="item-list">
<ul>
<li class="views-row views-row-1 views-row-odd views-row-first"> </li>
<li class="views-row views-row-2 views-row-even "> </li>
Now how do i inject a div in each of these li.. Is this possible without using jquery?
If you go the the "Edit" page for the view, you should see a link called "Theme: Information". It's under the "Style Settings" section. If you click this, you can see a list of all the possible template that your theme will look for when displaying the view. In bold will be the file it is currently using.
views-view--myview.tpl.php is to high up the chain to do what you want. If you want to inject a div (the same div) around each field you output, then I think the file views-view-field.tpl.php is what you are looking for.
The file contains just the line
<?php print $output; ?>
So there you can insert the desired div (after you copy it from views/themes into the template directory for your theme, of course).
If you investigate the Theme Information link some more it describes how to be even more specific in naming the view template files, for example if you wanted to theme a specific row differently you could use the file views-view-field--entity-id-X.
Hope that helps!
EDIT for comment
To go a different route, you can also edit the field settings for your view. Under the Field tab on the edit view page, you can click the links for each field. There is a Suffix setting available you could use to inject a div after the field is displayed.

Categories