Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By drupalninja99 on
How do I add smarty vars without hacking the engine or creating a {set_vars} template function?
Comments
adding smarty variables
You can add items to the $node object in a module and these will be available in the smarty template.
It works, but it feels too much like a workaround. There is a 'set' method in the engine and stand alone variable names in the example templates, so it seems like there should be a better way to add smarty variables.
I'm not sure what the 'correct' process to do this is.
The 'correct' way depends on
The 'correct' way depends on your approach -- i.e. is this for rendering a specific themable function or a general page/page element?
Please give a little more detail.
Thanks for the reply...
...oh so long ago. For that project, it was for a custom mod page element. That project is long gone though and I'm on to a new one. I'm using Drupal again oddly enough. Your reply is greatly appriciated since I may end up using Smarty templates again for this project as well.
Following up..
I didn't get a response from the original poster.
Just to clear up future searches:
Implementing a _smarty_variables function within the theme-specific smartytemplate.php file is the most direct route.
See:
http://drupal.org/node/16383 and replace 'phptemplate' with 'smarty'
Also:
http://drupal.org/node/55221
great stuff
thanks for the answer--that's finally what I needed. I had resorted to calling a smarty function at the top called set_vars but this is a much cleaner solution.
what type of stuff is in the $hook variable--I'm not sure what that's used for?
See
See http://api.drupal.org/api/4.7/group/hooks for some examples.
Just drupal_set_message($hook) and see what you get.
It allows you to act differently in terms of variable addition for the type of template being served up (i.e. a block vs a comment).