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

Accessing data from Parent Template

 
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
darksinclair
Smarty n00b


Joined: 15 Aug 2006
Posts: 2
Location: Waterloo, ON, CAN

PostPosted: Tue Aug 15, 2006 2:43 am    Post subject: Accessing data from Parent Template Reply with quote

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


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Aug 15, 2006 7:01 am    Post subject: Re: Accessing data from Parent Template Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
robothero
Smarty n00b


Joined: 12 Aug 2006
Posts: 2

PostPosted: Tue Aug 15, 2006 7:24 am    Post subject: Re: Accessing data from Parent Template Reply with quote

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
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