Extra content block without extra template?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Extra content block without extra template?

Post 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?
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

Re: Extra content block without extra template?

Post 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}
"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!
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Re: Extra content block without extra template?

Post 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.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

Re: Extra content block without extra template?

Post 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.
"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!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Extra content block without extra template?

Post by velden »

Read this article.

It would involve a second template but using template inheritance I can't think of any disadvantage.
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Re: Extra content block without extra template?

Post 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.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Extra content block without extra template?

Post 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.
Post Reply

Return to “CMSMS Core”