Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
find variables required to render a given template

 
Post new topic   Reply to topic    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:   
Post new topic   Reply to topic    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