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

Nested blocks and parent issue

 
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
bluejester
Smarty Regular


Joined: 26 Apr 2012
Posts: 55

PostPosted: Wed Sep 25, 2013 2:38 pm    Post subject: Nested blocks and parent issue Reply with quote

Hello guys,

I'm having an issue with nested blocks and getting infos from the parent. Here's how to reproduce :

File A.tpl :
Code:

{block 'FooAndBar'}
   <div id="FooAndBar">
   
      Some "A.tpl" text...
   
      {block 'Foo'}
         <div id="Foo">
            Hey I'm Foo
         </div>
      {/block}
      
      {block 'Bar'}
         <div id="Bar">
            Hey I'm Bar
         </div>
      {/block}
   </div>
{/block}


File B.tpl :
Code:

{block 'FooAndBar'}
   <div id="FooAndBar">
   
      Some "B.tpl" text...
   
      <!-- I don't wan't the Foo block to be displayed anymore -->
      {block 'Foo'}         
      {/block}
      
      <!-- I want to get the parent Bar block -->
      {block 'Bar'}
         {$smarty.block.parent}
      {/block}
   </div>
{/block}


Code:

$Smarty->Display('extends:A.tpl|B.tpl');


Expected result :
Code:

<div id="FooAndBar">   
   
   Some "B.tpl" text...   
   
   <!-- I don't wan't the Foo block to be displayed anymore -->
   
   <!-- I want to get the parent Bar block -->
   <div id="Bar">
      Hey I'm Bar
   </div>
</div>


What I get :
Code:

<div id="FooAndBar">

   Some "B.tpl" text...

   <!-- I don't wan't the Foo block to be displayed anymore -->
               
   <!-- I want to get the parent Bar block -->      
         
   <div id="FooAndBar">

      Some "A.tpl" text...
      
         <div id="Foo">
            Hey I'm Foo
         </div>
      
      
      
         <div id="Bar">
            Hey I'm Bar
         </div>
      
   </div>   
</div>


It looks like {$smarty.block.parent} refers to the root block element 'FooBar' instead of 'Bar'.
Is it normal ?

Thanks,
Ben

PS : Smarty 3.1.14. Smile
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Sep 25, 2013 6:36 pm    Post subject: Reply with quote

Hi Ben

Yes, its normal. {$smarty.block.parent} returns always the outer parent block.

Otherwise there it will be ambiguous as the parent could have blocks with same name muitiple times.

Also the child would normally replace the complete outerlevel parent.

There was some discussion longer time ago about it and the result was that there was no consens on other solution beside returning the outer level block.
Back to top
View user's profile Send private message
bluejester
Smarty Regular


Joined: 26 Apr 2012
Posts: 55

PostPosted: Thu Sep 26, 2013 10:15 am    Post subject: Reply with quote

Hi Uwe,

OK, I understand, and I'll deal with it.

Thanks for your quick reply !
Ben
Back to top
View user's profile Send private message Visit poster's website
UnstoppableCarl
Smarty n00b


Joined: 10 Oct 2013
Posts: 3

PostPosted: Fri Oct 11, 2013 1:46 pm    Post subject: Reply with quote

This is really frustrating. I could do so much more with my templates if I didn't have this limitation.
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