use phptemplate variables
Making additional variables available to your templates
Task · add phptemplate variables · PHPTemplate variables · use phptemplate variables · Developers and coders · Themers · Drupal 4.7.x · Drupal 5.x
Last modified: August 26, 2009 - 23:47
Examples from this forum discussion. The $hook refers to the area the variable is to be used in (e.g. for comment.tpl.php, it would be "comment").
This function needs to be defined in a template.php file, which is placed inside the template directory (for instance : themes/box_cleanslate/template.php)
<?php
function _phptemplate_variables($hook, $vars) {
switch($hook) {
case 'comment' :
$vars['newvar'] = 'new variable';
$vars['title'] = 'new title';
break;
}
return $vars;
}
?>The output of this function is merged with the variables returned from phptemplate_comment, so you can easily adjust whichever variables you feel necessary.
Your comment.tpl.php file will now have a new variable available in it
called $newvar. Similarly the $title variable will be overridden with the value specified in
the function.
» 6 comments · Read more
