Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

overwrite multiple {block}s with same name in a template

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
stuff@s-misch.de
Smarty n00b


Joined: 03 Jun 2011
Posts: 2

PostPosted: Mon Oct 28, 2013 10:37 pm    Post subject: overwrite multiple {block}s with same name in a template Reply with quote

Hi guys,

I used to have one template for the website's html scaffolding and overwrite a {block content} via child templates, that provide the current page's content. The child template's content should also be send to the browser without scaffolding if the request has been done via ajax.

example:

parent.html

Code:
{if $ajax}
   {block content}{/block}
{else}
<html>
<body>
<div id="content">
   {block content} parent content (for example 404 stuff) {/block}
</div>
</body>
</html>
{/if}


child.html

Code:
{extends file="parent.html"}

{block content} child content {/block}


This approach worked fine in Smarty 3.1.13 and possibly 3.1.14, but stopped working in 3.1-DEV. The problem is that only the first {block content} is overwritten. The second one is left unchanged with the parent's default content.

My question now is whether this behaviour is intended or considered a bug: Should I be able to put multiple blocks with the same name into a template and should they all be overwritten by children?

best regards
Sebastian
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Oct 29, 2013 12:41 am    Post subject: Reply with quote

The bugfix is now in the SVN trunk
and will later be included in 3.1.16
Back to top
View user's profile Send private message
stuff@s-misch.de
Smarty n00b


Joined: 03 Jun 2011
Posts: 2

PostPosted: Tue Oct 29, 2013 9:11 am    Post subject: Reply with quote

Works perfectly. Thanks for your great work, Uwe.
Back to top
View user's profile Send private message
steveb321
Smarty Rookie


Joined: 14 Jul 2011
Posts: 8

PostPosted: Wed Nov 27, 2013 5:25 pm    Post subject: Reply with quote

U.Tews wrote:
The bugfix is now in the SVN trunk
and will later be included in 3.1.16


What commit fixes this - or can you provide a patch? I've been working on upgrading to smarty 3.1.15 but this bug is blocking...
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Nov 27, 2013 8:44 pm    Post subject: Reply with quote

You can check out the SVN trunk version

svn checkout http://smarty-php.googlecode.com/svn/trunk/
Back to top
View user's profile Send private message
steveb321
Smarty Rookie


Joined: 14 Jul 2011
Posts: 8

PostPosted: Mon Dec 02, 2013 4:10 pm    Post subject: Reply with quote

U.Tews wrote:
You can check out the SVN trunk version

svn checkout http://smarty-php.googlecode.com/svn/trunk/



Hi,

I'm still seeing a bug with extending templates in trunk - but its gone if I use the 3.1 dev tree...

The 3.1 dev tree seems to have a few debug lines still in there... e.g. an "echo 'lll';" in libs/sysplugins/smarty_internal_compile_extends.php


Here's the stripped down version of the template we're using (it extends another template) - what's happening is pane_middle defined at the bototm of the template never overrides pane_middle thats defined in pane earlier...

Code:
{block name='meta_description'}{/block}
{block name=container_class}no-pattern rewards_browser{/block}
{block name=pane_header}Rewards Store{/block}
{block name=pane_top}{/block}

{block name=pane}
    {block name="container_top"}
    {/block}

      {block name=pane_middle}
      {/block}
      {block name=pane_bottom}
      {/block}
{/block}


{block name=container_top}
  Container TOP
{/block}

{block name=pane_middle}
  PANE CONTENT
{/block}

Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Dec 02, 2013 6:25 pm    Post subject: Reply with quote

Blocks should be overwritten by blocks in child templates of the current template, but never by blocks in the same template.

If this did happen in some earlier version it was a bug.
The earlier versions did have some constellations where it did use the wrong context when resolving inheritance, especially with nested blocks.
That was the reason for an internal rewrite of inheritance processing for 3.1.15.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP