|
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 |
Nanne Smarty n00b
Joined: 14 Mar 2017 Posts: 3
|
Posted: Tue Mar 14, 2017 1:36 pm Post subject: extends with append blocks |
|
|
It might be that this is intended, but if it is, I don't know what the logic behind it is.
If we have the following three templates:
grandparent.tpl:
Code: |
{block name='test'}Test only the grandparent{/block}
|
parent.tpl
Code: |
{extends file='grandparent.tpl'}
{block name='test' append} with parent appended{/block}
|
child.tpl
Code: |
{extends file='parent.tpl'}
{block name='test'}This is only the child{/block}
|
I would expect the child to override the block. But this is not what happens.
This compiles to (see test-file below):
Quote: |
Smarty version:3.1.30
grandparent:
Test only the grandparent
parent:
Test only the grandparent with parent appended
child:
Test only the grandparentThis is only the child
|
I would expect the child's template to compile to
Quote: | This is only the child |
Especially, as the manual says "The {block} template source area of a child template will replace the correponding areas in the parent template(s).". So if I look at just te child, I would expect this block to replace everything. Might this be a bug? (it seems to me that it is, but the bugs-forum was very 'if you are not sure go to general', so here I am )
-----
My testfile:
Code: |
<?php
$smarty = new Smarty();
echo 'Smarty version:'.Smarty::SMARTY_VERSION.PHP_EOL;
echo "grandparent:".PHP_EOL;
echo $smarty->fetch('grandparent.tpl').PHP_EOL;
echo "parent:".PHP_EOL;
echo $smarty->fetch('parent.tpl').PHP_EOL;
echo "child:".PHP_EOL;
echo $smarty->fetch('child.tpl').PHP_EOL;
|
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Mar 14, 2017 4:15 pm Post subject: |
|
|
Template inheritance is now dynamic both at compile and cache time.
I can see how the issue you observe makes sense, but I can't say if this should be treated as bug. More like an undefined behavior.
Normally I'd expect prepend/append to be used transparently through inheritance chain. |
|
Back to top |
|
Nanne Smarty n00b
Joined: 14 Mar 2017 Posts: 3
|
Posted: Tue Mar 14, 2017 4:30 pm Post subject: |
|
|
AnrDaemon wrote: |
Normally I'd expect prepend/append to be used transparently through inheritance chain. |
Can you explain what you mean? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Mar 14, 2017 7:21 pm Post subject: |
|
|
I mean that if you used append once, you would continue to use it in extending templates. |
|
Back to top |
|
Nanne Smarty n00b
Joined: 14 Mar 2017 Posts: 3
|
Posted: Wed Mar 15, 2017 10:46 am Post subject: |
|
|
AnrDaemon wrote: | I mean that if you used append once, you would continue to use it in extending templates. |
Hmm, I don't agree. Maybe from a use-case scenario you would expect this to happen quite often, but from a technical point of view I would expect that looking at a template that implements a block that you can see there if it's the whole thing, or that an append happens.
Just like with a function that might call it's parent function: probably if one function in the parent-tree does this, you might expect more to do this, but if you don't you should be able to have that behaviour.
I believe this is a bug in the code, but in the least its a bug in the documentation. |
|
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
|