|
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 |
bluejester Smarty Regular
Joined: 26 Apr 2012 Posts: 55
|
Posted: Wed Sep 25, 2013 2:38 pm Post subject: Nested blocks and parent issue |
|
|
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. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Sep 25, 2013 6:36 pm Post subject: |
|
|
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 |
|
bluejester Smarty Regular
Joined: 26 Apr 2012 Posts: 55
|
Posted: Thu Sep 26, 2013 10:15 am Post subject: |
|
|
Hi Uwe,
OK, I understand, and I'll deal with it.
Thanks for your quick reply !
Ben |
|
Back to top |
|
UnstoppableCarl Smarty n00b
Joined: 10 Oct 2013 Posts: 3
|
Posted: Fri Oct 11, 2013 1:46 pm Post subject: |
|
|
This is really frustrating. I could do so much more with my templates if I didn't have this limitation. |
|
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
|