[SOLVED] Smarty Template Inheritance and Defined ContenT

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
lewishowles
Forum Members
Forum Members
Posts: 52
Joined: Tue Oct 25, 2011 4:45 pm
Location: Lancashire, UK

[SOLVED] Smarty Template Inheritance and Defined ContenT

Post by lewishowles »

It appears that using when using the new Smarty template inheritance idea, some odd things happen. It seems that even if you replace the contents of a block, it's still being parsed. I have this in my main template:

Code: Select all

{block name='content_area'}
   <div class="header clearing">
      {content assign='subtitle' block='subtitle' label='Page Subtitle'}
      <h2>{$subtitle}</h2>
      {content assign='pagelink' block='pagelink' label='Page Link'}
      {content assign='pagelinktext' block='pagelinktext' label='Page Link Text'}
      {if $pagelink != '' && $pagelinktext != ''}
         <a href="{cms_selflink href=$pagelink}" class="button more">{$pagelinktext}</a>
      {/if}
   </div>

   <div class="wrapper">
      {$main_content}

      {if $pagelink != '' && $pagelinktext != ''}
         <a href="{cms_selflink href=$pagelink}" class="button mobile">{$pagelinktext}</a>
      {/if}
   </div>
{/block}
Then in a secondary template I have this:

Code: Select all

{extends file='template:Default'}

{block name='content_area'}
    {$main_content}
{/block}

I've had to assign {content} to {$main_content} because it was complaining about duplicating the main content block, which is what makes me think it parses it even if you replace the contents of the block in the sub-template.

This isn't too bad for just the content block as assigning it isn't very difficult - but it means all of the content blocks defined in the original template (which I don't want in the sub template) still appear on the sub template page.

Is this the expected behaviour or am I missing something? Is there another way to do it without creating a separate template?

Or is the easiest way to have a master template that has neither set of content, then two templates that extend it - one for the set of content blocks and one for the simplified content?
Last edited by lewishowles on Wed Dec 12, 2012 1:14 pm, edited 1 time in total.
fredp
Forum Members
Forum Members
Posts: 218
Joined: Sun Jul 27, 2008 1:36 am
Location: USA

Re: Smarty Template Inheritance and Defined Content Blocks

Post by fredp »

Hi,

I suspect that you're seeing caching effects. You might want to review the CMSMS and Smarty cache related docs (e.g, CMSMS caching and Smarty cacheability).

In particular...
Special notes for Site developers

Due to limitations in Smarty3, when caching for a page is enabled, special consideration must be used to capture the output of a non-cached plugin. In order to capture the output of a plugin that does not cache, you need to use either the "capture" smarty compiler tag, or the "nocache" tag attribute. i.e:

{capture assign='mycontent'}{content}{/capture} or {content assign='mycontent'}{$mycontent nocache}
You could try adding a "nocache" option to your {$main_content} tag in your secondary template to see if that gets you closer to your desired results:
{$main_content nocache}
Hope this helps,
fredp
Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Smarty Template Inheritance and Defined Content Blocks

Post by calguy1000 »

The {content} tag is a compiler tag which means yes, it gets parsed in sub templates.

If you want to have child templates that have extra content blocks that should be fine. However, you cannot remove, or hide content blocks in child templates.
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.
lewishowles
Forum Members
Forum Members
Posts: 52
Joined: Tue Oct 25, 2011 4:45 pm
Location: Lancashire, UK

Re: Smarty Template Inheritance and Defined Content Blocks

Post by lewishowles »

That's what I was suspecting. That's a shame, but it's not too big a deal to have one master and two different sub for the different sets of content blocks. Thanks!
Post Reply

Return to “CMSMS Core”