Smarty Block Inheritance Inconsistencies

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.
Locked
MantaPro
Forum Members
Forum Members
Posts: 97
Joined: Sun Feb 03, 2008 8:14 pm

Smarty Block Inheritance Inconsistencies

Post by MantaPro »

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

Code: Select all

{block name="block1}
{content}
{/block}
And the child template that extends the parent could have

Code: Select all

{block="block1"
{content}
{content block="other stuff" label="Label"}
{/block}
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

Code: Select all

{block="block1"}
{content block="other stuff" label="Other Stuff" priority=20}
{/block}
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.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1609
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Smarty Block Inheritance Inconsistencies

Post by DIGI3 »

Assign the main content block to a variable first, e.g.

Code: Select all

{$mycontent="{content}" scope=global}
Then in your child templates you can still output it

Code: Select all

{$mycontent}
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.
Not getting the answer you need? CMSMS support options
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Smarty Block Inheritance Inconsistencies

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
MantaPro
Forum Members
Forum Members
Posts: 97
Joined: Sun Feb 03, 2008 8:14 pm

Re: Smarty Block Inheritance Inconsistencies

Post by MantaPro »

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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Smarty Block Inheritance Inconsistencies

Post by calguy1000 »

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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
MantaPro
Forum Members
Forum Members
Posts: 97
Joined: Sun Feb 03, 2008 8:14 pm

Re: Smarty Block Inheritance Inconsistencies

Post by MantaPro »

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
Locked

Return to “CMSMS Core”