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

extends with append blocks

 
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 -> General
View previous topic :: View next topic  
Author Message
Nanne
Smarty n00b


Joined: 14 Mar 2017
Posts: 3

PostPosted: Tue Mar 14, 2017 1:36 pm    Post subject: extends with append blocks Reply with quote

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 Smile )


-----
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
View user's profile Send private message Send e-mail
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Mar 14, 2017 4:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
Nanne
Smarty n00b


Joined: 14 Mar 2017
Posts: 3

PostPosted: Tue Mar 14, 2017 4:30 pm    Post subject: Reply with quote

AnrDaemon wrote:

Normally I'd expect prepend/append to be used transparently through inheritance chain.


Can you explain what you mean?
Back to top
View user's profile Send private message Send e-mail
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Mar 14, 2017 7:21 pm    Post subject: Reply with quote

I mean that if you used append once, you would continue to use it in extending templates.
Back to top
View user's profile Send private message
Nanne
Smarty n00b


Joined: 14 Mar 2017
Posts: 3

PostPosted: Wed Mar 15, 2017 10:46 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
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 -> General 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