|
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 |
darksinclair Smarty n00b
Joined: 15 Aug 2006 Posts: 2 Location: Waterloo, ON, CAN
|
Posted: Tue Aug 15, 2006 2:43 am Post subject: Accessing data from Parent Template |
|
|
Greetings,
Essentially, what I want to do is this:
in parent.tpl:
{foreach item=current from=$contacts}
{if (a)}
{include file="child_a.tpl"}
{include file="child_b.tpl"}
{else}
{include file="child_b.tpl"}
{include file="child_a.tpl"}
{/if}
{/foreach}
in child_a.tpl
{$current.AName}
in child_b.tpl
{$current.BName}
But, I am finding that I cannot access the parent value $current from the 'child' templates child_a.tpl and child_b.tpl... is this a security feature of Smarty to have localized variables? Is there a way to extend the parent variable $current to the child?
P.S. If I substitute the actual code in child_a and child_b into parent.tpl then everything works fine.. but as I may call child_a and child_b a couple dozen times depending on configurations... I'd rather have these two componentized sub-templates which can access the parents values.
Thanks in advance! |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Aug 15, 2006 7:01 am Post subject: Re: Accessing data from Parent Template |
|
|
darksinclair wrote: | But, I am finding that I cannot access the parent value $current from the 'child' templates child_a.tpl and child_b.tpl. |
Works fine for me. |
|
Back to top |
|
robothero Smarty n00b
Joined: 12 Aug 2006 Posts: 2
|
Posted: Tue Aug 15, 2006 7:24 am Post subject: Re: Accessing data from Parent Template |
|
|
darksinclair wrote: | is this a security feature of Smarty to have localized variables? | The documentation says the opposite should be true:
Smarty docs 2.6.11 page 45 wrote: | Any variables available in the current template are also available within the included template. |
So you probably made a typo with the variable's spelling or left off a $ or something. |
|
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
|