Page 1 of 1
Extra content block without extra template?
Posted: Sat May 24, 2014 7:33 am
by Cerulean
I know that usually if you need different content blocks on different pages you use different templates for those pages.
But there is one page in my site where I need an additional content block and I'm wondering if I can achieve this without creating an additional template just for this page. Is there any way to use Smarty logic in a template to display an additional content block in the admin? Or some technique using the page's field for "Smarty data or logic that is specific to this page"?
Or is an additional template the only way?
Re: Extra content block without extra template?
Posted: Sat May 24, 2014 8:53 am
by Jo Morg
Use something like this right after the {process_pagedata} tag on top of the template:
Code: Select all
{content block='sidebar' label='Sidebar' assign='sidebar'}
then use something like this where you need to show the block:
Code: Select all
{if !isset($sidebar)}{$sidebar}{/if}
or
Code: Select all
{if !isset($sidebar) && $page_alias == 'foo'}{$sidebar}{/if}
Re: Extra content block without extra template?
Posted: Sat May 24, 2014 9:32 am
by Cerulean
Thanks for the reply, but that method uses logic to show or hide the block on the frontend, and the block appears in the admin backend for every page that uses the template.
What I want is a block that appears in the backend only for a particular page.
Re: Extra content block without extra template?
Posted: Sat May 24, 2014 10:32 am
by Jo Morg
There is no way to dynamically show or hide a content block on the admin side with template logic, other than by changing templates. At least not with core. I don't think there is a 3rd party module capable of doing that either, but I might be wrong.
Re: Extra content block without extra template?
Posted: Sat May 24, 2014 6:24 pm
by velden
Read
this article.
It would involve a second template but using template inheritance I can't think of any disadvantage.
Re: Extra content block without extra template?
Posted: Sat May 24, 2014 11:39 pm
by Cerulean
Thanks velden, some useful tips in that article.
Doesn't quite achieve what I was hoping for though...
{include}
You can use template logic such as "if $page_alias ==" to control if the included template is pulled in, but this only works on the frontend. If there's a content block in the included template this doesn't appear in the admin, probably because $page_alias and other Smarty variables from the master template aren't available or the logic just isn't processed there. So, not being able to use template logic to control the appearance of the additional content block in the admin, it's the same result as just putting the additional content block directly into the master template.
Template inheritance
A nice way to add an additional template without duplicating code, but again it doesn't allow the use of template logic to control which content blocks appear in the admin. That is, I can't pull in the extending template based on logic in the master template. E.g. I can't specify the extending template to be used based on page alias or if a page is a child of a particular page. The extending template has to be set manually for pages in the admin, so if my client adds a page I have to have them select the appropriate template which was one of the things I was aiming to avoid.
So it looks like manually setting a new template for certain pages in the admin is the only way. No big deal, and I've learned some new techniques, thanks.
Re: Extra content block without extra template?
Posted: Sun May 25, 2014 8:08 am
by velden
Note that it is easy to move the 'select template' dropdown from the 'Options' tab to the 'Main' tab. Probably easier voor editors to remember to change template.
And/or you could learn them to Copy an existing page.