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

{include} and passing the contents of an object

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


Joined: 12 Aug 2006
Posts: 2

PostPosted: Sat Aug 12, 2006 11:43 pm    Post subject: {include} and passing the contents of an object Reply with quote

I've just started teaching myself Smarty to use on a Drupal site.

I'm trying to create a template that includes a list of other nodes, which will be formatted according to their own template.

I understand I can include another template with {include} but the doc says "Any variables available in the current template
are also available within the included template."

Now, my parent node will have $title $content $date etc. as variables. But it also has $nodes which is an array of its child nodes. When I {include} their templates, I want them to use $nodes[$x]->title not $title.

But I'm sure you agree that writing
Code:
{include file="childnode.tpl" title="$nodes[$x]->title" content="$nodes[$x]->content" date="$nodes[$x]->date" }

is not a great solution, because then the parent template must know the name of every variable the child template needs.

I could also have the child template pull its variables out of $node[$x] itself, but I want to be able to use the same template file that I use when the child node is being viewed directly.

Is there a variable name such as $_self that I can assign the whole node to? What's the best way to pass all the node's properties as variables?
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