|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
gtozzi Smarty Rookie
Joined: 18 Mar 2017 Posts: 8
|
Posted: Sat Mar 18, 2017 5:55 pm Post subject: Block append and prepend directives override eachother |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Mar 19, 2017 12:34 am Post subject: |
|
|
Works as intended. |
|
Back to top |
|
gtozzi Smarty Rookie
Joined: 18 Mar 2017 Posts: 8
|
Posted: Sun Mar 19, 2017 2:12 am Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
scuzzy Smarty Regular
Joined: 31 Aug 2003 Posts: 84
|
Posted: Sat May 12, 2018 7:36 am Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat May 12, 2018 2:10 pm Post subject: |
|
|
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 |
|
|
|
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
|