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

Extending nested blocks, keep children

 
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
AlexG.
Smarty n00b


Joined: 12 Aug 2016
Posts: 3

PostPosted: Fri Aug 12, 2016 8:42 am    Post subject: Extending nested blocks, keep children Reply with quote

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


Joined: 10 Jan 2011
Posts: 96

PostPosted: Fri Aug 12, 2016 11:38 am    Post subject: Reply with quote

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


Joined: 12 Aug 2016
Posts: 3

PostPosted: Fri Aug 12, 2016 1:10 pm    Post subject: Reply with quote

Unfortunatly that didn't help, but as stated it wasnt a direct answer. Thanks anyways for the effort Smile
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Aug 12, 2016 2:01 pm    Post subject: Reply with quote

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


Joined: 12 Aug 2016
Posts: 3

PostPosted: Tue Aug 16, 2016 7:23 am    Post subject: Reply with quote

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


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Aug 18, 2016 12:35 am    Post subject: Reply with quote

Nesting blocks are useful, only when you specifically want that behavior. Like in my example.
Back to top
View user's profile Send private message
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