CMS Made Simple Forums

Smarty Block Inheritance Inconsistencies
Page 1 of 1

Author:  MantaPro [ Sun Feb 10, 2019 1:06 am ]
Post subject:  Smarty Block Inheritance Inconsistencies

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" 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

{block name="block1}

And the child template that extends the parent could have

{content block="other stuff" label="Label"}

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 the above now throws an error message "Duplicate content-en blocks"

If I change the child template to

{content block="other stuff" label="Other Stuff" priority=20}

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.

Author:  DIGI3 [ Sun Feb 10, 2019 2:03 am ]
Post subject:  Re: Smarty Block Inheritance Inconsistencies

Assign the main content block to a variable first, e.g.
{$mycontent="{content}" scope=global}

Then in your child templates you can still output it

This is good practice for all content blocks as it gives you control over the scope and placement without needing to worry about the order.

Author:  Rolf [ Sun Feb 10, 2019 11:02 am ]
Post subject:  Re: Smarty Block Inheritance Inconsistencies ... gn-manager

Author:  MantaPro [ Sun Feb 10, 2019 1:54 pm ]
Post subject:  Re: Smarty Block Inheritance Inconsistencies

Digi3 - Yes I know - thanks. That makes a work-around (of the issue that the block inheritance is being merged rather than replaced) workable.

Can't find the bug tracker for CMS core or Content-Manager. Is the root issue in CMSMS or is it Smarty that is compiling the templates incorrectly ? Or is this a planned deviation away from Smarty's Inheritance rules ?

Rolf - thanks for the link which explains with detailed code; these are exactly the kind of template structures I referred to and used in some of my earlie CMSMS v1.11 websites 5 years ago - I used to use Goran's I-Do-This website that had some excellent write ups of all this stuff - now all out of date and sadly been taken offline - but your CMSMS Can be Simple is awesome too and is also a go-to reference for how-tos - Goran used to have some good examples for inheritance - it is good to see you too have covered this topic with up to date CMSMS2 / Smarty3 example code - great thanks - but how it relates to my original post: if the blocks in your examples weren't appending then Smarty Inheritance remains broken within CMSMS2

Author:  calguy1000 [ Sun Feb 10, 2019 2:15 pm ]
Post subject:  Re: Smarty Block Inheritance Inconsistencies

This is neither a problem in Smarty OR a deviation in CMSMS.

The CMSMS Content editor does not 'fetch' the smarty template, it merely compiles it (which includes compiling all parent templates). It uses a {content} compiler tag to gather the list of content blocks.

It is invalid to have {content} multiple times in a smarty template, and in the compilation process there is no way to detect if two {content} tags are in the same template or are in child/parent templates in the same block in an inheritance scenario.

Author:  MantaPro [ Sun Feb 10, 2019 3:38 pm ]
Post subject:  Re: Smarty Block Inheritance Inconsistencies

Thanks for the clarification Calguy

Used to work as per Smarty Docs in CMSMS V1.

When the {content} complier tags are gathered; then if a block appends or prepends a parent block then if the the parent's {content} tag is in the block being added to is retained; but if it not being appended or prepend'ed then the parent's {content} tag within the replaced block ought to be ignored because the whole block is being replaced the childs block, And if that child block contains a {content} tag then that isn't an error, it isnt duplicating the parent - it is replacing it. If the block in the child template omits the {content} block then that is an error.

The point of this post was to bring this behaviour to the Dev Team attention given it contradicts how template inheritance is described in the Smarty Documentation.

Consider it a bug or not as you will - thanks again all for your replies and the magnificent work you do with this software

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group