|
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 |
AlexG. Smarty n00b
Joined: 12 Aug 2016 Posts: 3
|
Posted: Fri Aug 12, 2016 8:42 am Post subject: Extending nested blocks, keep children |
|
|
When extending a template, is it possible to change a blocks parent without affecting its nested children? I've tried {$smarty.block.parent}, but it displays the outer parents content, not the block itself.
parent.tpl
Code: | {block name="block_parent"}
<div class="parent">
<h1>Parent Title</h1>
{block name="block_child"}
<div class="child">Child</div>
{/block}
</div>
{/block} |
child.tpl
Code: | {extends file="parent.tpl"}
{block name="block_parent"}
<div class="changed--parent">
<h1>Parent Title changed</h1>
{block name="block_child"}
{* something like this for example *}
{$smarty.block.self}
{/block}
</div>
{/block} |
Desired output
Code: | <div class="changed--parent">
<h1>Parent Title changed</h1>
<div class="child">Child</div>
</div> |
|
|
Back to top |
|
Aristophan Smarty Regular
Joined: 10 Jan 2011 Posts: 96
|
Posted: Fri Aug 12, 2016 11:38 am Post subject: |
|
|
Hi
Not directly an answer to your question, though maybe this answer will help you to clear things up. (I personally haven't yet played around with inheritance, so I can't give advice myself.)
https://github.com/smarty-php/smarty/issues/234 |
|
Back to top |
|
AlexG. Smarty n00b
Joined: 12 Aug 2016 Posts: 3
|
Posted: Fri Aug 12, 2016 1:10 pm Post subject: |
|
|
Unfortunatly that didn't help, but as stated it wasnt a direct answer. Thanks anyways for the effort |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Aug 12, 2016 2:01 pm Post subject: |
|
|
Simple answer is - do NOT nest blocks.
The results in such case are least predictable and works by pure accident.
You CAN use "prepend/append" to parent blocks. But I would not recommend it and evaluate possible maintenance impacts first.
P.S.
One useful case for template extension I've found is http://www.smarty.net/forums/viewtopic.php?t=25486 |
|
Back to top |
|
AlexG. Smarty n00b
Joined: 12 Aug 2016 Posts: 3
|
Posted: Tue Aug 16, 2016 7:23 am Post subject: |
|
|
Imo nesting blocks is very usefull, building html without nesting elements doesn't work very well, right? The blocks are nested and I cannot change that, Shopware and Oxid set that standard. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Aug 18, 2016 12:35 am Post subject: |
|
|
Nesting blocks are useful, only when you specifically want that behavior. Like in my example. |
|
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
|