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

Block append and prepend directives override eachother

 
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
gtozzi
Smarty Rookie


Joined: 18 Mar 2017
Posts: 8

PostPosted: Sat Mar 18, 2017 5:55 pm    Post subject: Block append and prepend directives override eachother Reply with quote

Hi there!

I've been using Smarty for a very long time and this is the first time (maybe) I found a bug so, first of all, let me express my gratitude and congratulations for creating such a stable, robust easy to use and and well-documented template engine.

I may have found a bug. I have a base template and a child template. I override the same block twice in the child template: the first time to append, the second time to prepend. Apparently, the last time "wins": both overrides will append or prepend, depending on which one is specified last.

Base template:
Code:

{{* Generic form input widget *}}
{{strip}}
   {{if ! isset($type)}}
      {{$type='text'}}
   {{/if}}
{{/strip}}<div class="form-group row">
   <label for="{{$name}}" class="col-sm-2 col-form-label">{{$label}}</label>
   <div class="col-sm-10">
      {{block name='input'}}
         <input type="{{$type}}" class="form-control" placeholder="{{$placeholder}}" name="{{$name}}" value="{{$value}}">
      {{/block}}
   </div>
</div>


Child template:
Code:

{{extends file='./input.tpl'}}
{{block name='input' prepend}}
   <div class="input-group">
{{/block}}
{{block name='input' append}}
   <span class="input-group-btn">
      <button class="btn btn-error" type="button">Disabilita</button>
   </span>
</div>
{{/block}}


Actual output:
Code:

<div class="form-group row">
   <label for="password" class="col-sm-2 col-form-label">Password</label>
   <div class="col-sm-10">
      
         <input type="password" class="form-control" placeholder="Lascia vuoto per non modificare" name="password" value="">
      
   <div class="input-group">

   <span class="input-group-btn">
      <button class="btn btn-error" type="button">Disabilita</button>
   </span>
</div>

   </div>
</div>


What i would expect:
Code:

<div class="form-group row">
   <label for="password" class="col-sm-2 col-form-label">Password</label>
   <div class="col-sm-10">
   <div class="input-group">
      
         <input type="password" class="form-control" placeholder="Lascia vuoto per non modificare" name="password" value="">
      
   <span class="input-group-btn">
      <button class="btn btn-error" type="button">Disabilita</button>
   </span>
</div>

   </div>
</div>
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Mar 19, 2017 12:34 am    Post subject: Reply with quote

Works as intended.
Back to top
View user's profile Send private message
gtozzi
Smarty Rookie


Joined: 18 Mar 2017
Posts: 8

PostPosted: Sun Mar 19, 2017 2:12 am    Post subject: Reply with quote

Thank you for your reply.

Could you please explain me what is the intended way to extend a block in a "child" template by simultaneously appending and prepending to it?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Mar 19, 2017 5:24 pm    Post subject: Reply with quote

http://www.smarty.net/docs/en/language.function.block.tpl
Back to top
View user's profile Send private message
scuzzy
Smarty Regular


Joined: 31 Aug 2003
Posts: 84

PostPosted: Sat May 12, 2018 7:36 am    Post subject: Reply with quote

I agree with gtozzi, if you had

child.tpl
Code:
{extends file="parent.tpl"}
{block name="MyBlock" prepend}Start{/block}
{block name="MyBlock" append}End{/block}

parent.tpl
Code:
{block name="MyBlock"}Middle{/block}


What would make the output of "MiddleStartEnd" or " StartEndMiddle" based on which block is parsed last, the Intended Behavior?
Back to top
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat May 12, 2018 2:10 pm    Post subject: Reply with quote

You can't both prepend and append the same block.
If you need complex manipulation, use {parent}/{child} tags (or, in older versions, {$smarty.block.parent}/{$smarty.block.child}) to layout the block contents the way you want.
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