Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Block append and prepend directives override eachother

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
gtozzi
Smarty n00b


Joined: 18 Mar 2017
Posts: 2

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: 1032

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 n00b


Joined: 18 Mar 2017
Posts: 2

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: 1032

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
Display posts from previous:   
Post new topic   Reply to topic    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