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

find variables required to render a given 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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
flowtron
Smarty n00b


Joined: 24 May 2012
Posts: 1

PostPosted: Thu May 24, 2012 1:35 pm    Post subject: find variables required to render a given template Reply with quote

If you find the need to establish a list of variables used inside a template I found this way to get at one:
Code:

$node = $smarty->createTemplate( "whatever.tpl" );
$code = $node->compiler->compileTemplate( $node );
echo sprintf( "<pre>%s</pre>",
  print_r( $node->properties['variables'], true )
);

This will not list anything but the direct scope of the template; meaning nothing from any sub-templates! Use the getTags-function to establish included templates, then run the same on all of them.
Maybe the 3.2-development will provide us some nicer interface to the variables. On #smarty globe spoke of defaultVariableHandler - I'd say this should avoid the costly (extra) compilation Wink
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 -> Tips and Tricks 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