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

Passing smarty variables to an include var

 
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
appel
Smarty Rookie


Joined: 27 May 2003
Posts: 29

PostPosted: Tue Jul 01, 2003 4:07 pm    Post subject: Passing smarty variables to an include var Reply with quote

So, this is my code:

Code:

<ul>
{section name=i loop=$tree}
   <li>{$tree[i].page_name}</li>
   
   {include file="children.tpl" pages="$tree[i].Children"}
   
{/section}
</ul>


But passing $tree[i].Children as the variable "pages" to children.tpl doesn't work. What do I do?
Back to top
View user's profile Send private message
Scott
Smarty Rookie


Joined: 18 Apr 2003
Posts: 10
Location: Sarasota, FL

PostPosted: Tue Jul 01, 2003 10:17 pm    Post subject: Re: Passing smarty variables to an include var Reply with quote

appel wrote:
So, this is my code:

Code:

<ul>
{section name=i loop=$tree}
   <li>{$tree[i].page_name}</li>
   
   {include file="children.tpl" pages="$tree[i].Children"}
   
{/section}
</ul>


But passing $tree[i].Children as the variable "pages" to children.tpl doesn't work. What do I do?



Try using a temporary variable:

Code:

<ul>
{section name=i loop=$tree}
   <li>{$tree[i].page_name}</li>

   {assign var="tmp" value="$tree[i].Children"}
   {include file="children.tpl" pages="$tmp"}
   
{/section}
</ul>
Back to top
View user's profile Send private message Visit poster's website
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Wed Jul 02, 2003 8:10 am    Post subject: Reply with quote

This should work:
Code:

<ul>
{section name=i loop=$tree}
   <li>{$tree[i].page_name}</li>
   
   {include file="children.tpl" pages=$tree[i].Children}
   
{/section}
</ul>


Note that you DON'T NEED the quotes around $tree[i].Children. It is wrong to put them there!

Use quotes only for strings:
Code:

  {foo bar="this is a string"}
  {foo bar=$string}
  {foo bar="this is a string with an embedded `$variable`"}


See Smarty manual for further instructions
Back to top
View user's profile Send private message
appel
Smarty Rookie


Joined: 27 May 2003
Posts: 29

PostPosted: Wed Jul 02, 2003 10:18 am    Post subject: ty Reply with quote

yes, thanks. this works now.
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