Smarty Block Inheritance Inconsistencies
Posted: Sun Feb 10, 2019 1:06 am
Reworking my templates so that they never have smarty commands within content what will be edited by User Editors using MicroTiny
I've used Smarty inheritance since CMSMS V1.10 if not before, so a good few years - and also used to use AdvancedContent, but more recently CGContentUtils to enable a limited amount of selectable layout
But I note that in CMSMS V2, smarty inheritance seems a bit "broken"
https://www.smarty.net/docs/en/advanced ... itance.tpl This clearly shows that blocks in a child template that extend a parent template; the child block with the same block name replaces the parent (unless the append or prepend modifier is used).
And according to CMSMS documentation, a template must contain {content} without a block name.
So in CMSMS v1 the parent template code have
And the child template that extends the parent could have
This ought to work and used to in cmsms V1.x. According to normal Smarty inheritance the block1 in the child template REPLACES block1 in the parent template. And CMSMS' need for a {content} is always satisfied
Using CMSMS 2.2.9.1 the above now throws an error message "Duplicate content-en blocks"
If I change the child template to
and set {content priority=10} in the parent template then in Admin it displays what is detailed in this example 2 content blocks - but when you view the page in the front end you only get the other-stuff content block
So CMSMS seems to be complying with Smarty Inheritance rules in the front end (i.e. child block replaces parent) but not in the back end (child block is wrongly being merged with parent and therefore only one of them can have a {content} - And this used to work OK in cmsms V1.x
I am well aware that there are ways to work around these inconsistencies/errors; one of which is have a parent template with all of the main code in it - <head> jquery; css; nav & footers etc, but it has an empty {block}. Don't assign this template to a design
Then have numerous child templates with all of the variant layouts needed, each one containing a {block} that is merged with the empty parent in the back-end and replaces the empty block in the front end. Only assign these child templates to a Design (never the Parent - so that it can not be be selected by Content Manager); and make one of these child templates the default.
Works fine; perhaps even preferable; but FYI of the Dev Team if you aren't already aware, template inheritance no longer works as per Smarty documentation and CMSMS template documentation is pre V2.
I've used Smarty inheritance since CMSMS V1.10 if not before, so a good few years - and also used to use AdvancedContent, but more recently CGContentUtils to enable a limited amount of selectable layout
But I note that in CMSMS V2, smarty inheritance seems a bit "broken"
https://www.smarty.net/docs/en/advanced ... itance.tpl This clearly shows that blocks in a child template that extend a parent template; the child block with the same block name replaces the parent (unless the append or prepend modifier is used).
And according to CMSMS documentation, a template must contain {content} without a block name.
So in CMSMS v1 the parent template code have
Code: Select all
{block name="block1}
{content}
{/block}
Code: Select all
{block="block1"
{content}
{content block="other stuff" label="Label"}
{/block}
Using CMSMS 2.2.9.1 the above now throws an error message "Duplicate content-en blocks"
If I change the child template to
Code: Select all
{block="block1"}
{content block="other stuff" label="Other Stuff" priority=20}
{/block}
So CMSMS seems to be complying with Smarty Inheritance rules in the front end (i.e. child block replaces parent) but not in the back end (child block is wrongly being merged with parent and therefore only one of them can have a {content} - And this used to work OK in cmsms V1.x
I am well aware that there are ways to work around these inconsistencies/errors; one of which is have a parent template with all of the main code in it - <head> jquery; css; nav & footers etc, but it has an empty {block}. Don't assign this template to a design
Then have numerous child templates with all of the variant layouts needed, each one containing a {block} that is merged with the empty parent in the back-end and replaces the empty block in the front end. Only assign these child templates to a Design (never the Parent - so that it can not be be selected by Content Manager); and make one of these child templates the default.
Works fine; perhaps even preferable; but FYI of the Dev Team if you aren't already aware, template inheritance no longer works as per Smarty documentation and CMSMS template documentation is pre V2.