• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Smarty Block Inheritance Inconsistencies
PostPosted: Sun Feb 10, 2019 1:06 am 
Offline
Forum Members
Forum Members

Joined: Sun Feb 03, 2008 8:14 pm
Posts: 35
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.features.template.inheritance.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:
{block name="block1}
{content}
{/block}


And the child template that extends the parent could have

Code:
{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:
{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.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Smarty Block Inheritance Inconsistencies
PostPosted: Sun Feb 10, 2019 2:03 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Feb 25, 2009 4:25 am
Posts: 594
Location: Victoria, BC
Assign the main content block to a variable first, e.g.
Code:
{$mycontent="{content}" scope=global}

Then in your child templates you can still output it
Code:
{$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


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Smarty Block Inheritance Inconsistencies
PostPosted: Sun Feb 10, 2019 11:02 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Apr 23, 2008 7:53 am
Posts: 7617
Location: The Netherlands
https://cmscanbesimple.org/blog/the-pow ... gn-manager

_________________
Image

Did my post help you solving a problem at your (customers) website and it saved you many hours of work? Great!! Consider buying me a cup of coffee in return!



Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Smarty Block Inheritance Inconsistencies
PostPosted: Sun Feb 10, 2019 1:54 pm 
Offline
Forum Members
Forum Members

Joined: Sun Feb 03, 2008 8:14 pm
Posts: 35
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


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Smarty Block Inheritance Inconsistencies
PostPosted: Sun Feb 10, 2019 2:15 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

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


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Smarty Block Inheritance Inconsistencies
PostPosted: Sun Feb 10, 2019 3:38 pm 
Offline
Forum Members
Forum Members

Joined: Sun Feb 03, 2008 8:14 pm
Posts: 35
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


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Hosting Nation - Managed CMSMS Hosting