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?
Extra content block without extra template?
Re: Extra content block without extra template?
Use something like this right after the {process_pagedata} tag on top of the template:
then use something like this where you need to show the block:
or
Code: Select all
{content block='sidebar' label='Sidebar' assign='sidebar'}
Code: Select all
{if !isset($sidebar)}{$sidebar}{/if}
Code: Select all
{if !isset($sidebar) && $page_alias == 'foo'}{$sidebar}{/if}
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Re: Extra content block without extra template?
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.
What I want is a block that appears in the backend only for a particular page.
Re: Extra content block without extra template?
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.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Re: Extra content block without extra template?
Read this article.
It would involve a second template but using template inheritance I can't think of any disadvantage.
It would involve a second template but using template inheritance I can't think of any disadvantage.
Re: Extra content block without extra template?
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.
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?
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.
And/or you could learn them to Copy an existing page.