[SOLVED] How to extend templates?

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
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm

[SOLVED] How to extend templates?

Post by nervino »

Hi, I would nest a template in the Smarty's {block} tag.

I have a default template, called "Automotive default", with an empty footer block.

inside template "Automotive default" I put:

Code: Select all

{block name='footer'}{/block}
I also have made a template called "footer inner page" with some HTML inside.

Hence, I made a page template called "Inner page" that should extend "Automotive default", inserting the template "footer inner page" inside the "footer" block .

template: "Inner page"

Code: Select all

{extends file='template:Automotive default'}
{block name=footer}
How do I insert the template "footer inner page" here?

Code: Select all

{/block}
Is this a right way to use the new template's management of cmsms 2.x?


Thank you
Last edited by nervino on Sat Oct 24, 2015 11:08 am, edited 1 time in total.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

Re: How to extend templates?

Post by Jo Morg »

You are confusing different terms: extending VS including.
To extend a template you need to understand inheritance. Including a template is the closest there is to the old use of Global Content Blocks. And for that you don't need blocks, you just include another existing template by using {include file='cms_template:footer inner page'}. If you really want to use template inheritance you should start by reading the Smarty docs on the Smarty site. Inheritance is closely related with objects inheritance in programming, in that a template that extends another, inherits all the parents properties, and adds or overrides some of it's parents properties, keeping a designer from re-writing the same basic template over and over again...

http://www.smarty.net/docs/en/advanced. ... itance.tpl

http://docs.cmsmadesimple.org/introducing-cmsms-2-0

BTW template inheritance and inclusion have always been there, are Smarty features. We just optimized the way CMSMS uses these features.
"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!
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm

Re: How to extend templates?

Post by nervino »

Jo, thank you very much for your explanation.

My goal was to have a default template with an empty footer, then have other templates that extend the default one overriding the {block name='footer'}{/block} with the appropriate footer (this is a semplification as the templates are more complex).

Now it works.

By the way, is there any difference between
{include file='cms_template:footer inner page'}
and
{include file='template:footer inner page'}
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

Re: How to extend templates?

Post by Jo Morg »

nervino wrote:By the way, is there any difference between
{include file='cms_template:footer inner page'}
and
{include file='template:footer inner page'}
Yes: both are CMSMS template resources registered in Smarty, although the template has been deprecated and will eventually be removed.
"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!
Post Reply

Return to “CMSMS Core”