Where do I create PHPTemplate variables in Drupal theming?

<?php
function _phptemplate_variables($hook, $vars = array()) {
  switch (
$hook) {
    case
'page':
     
// code relating to variables for page templates here
      // EXAMPLE - is the current user logged in?
     
$vars['logged_in'] = ($user->uid > 0) ? TRUE : FALSE;
      break;

    case
'node':
     
// code relating to variables for node templates here
      // EXAMPLE - on front page teasers, make a comment count var using a query
     
if ($vars['teaser'] && $vars['is_front']) {
       
$vars['comment_count'] = db_result(db_query("SELECT comment_count
          from {node_comment_statistics} where nid = %d"
, $node->nid));
      }

      break;

    case
'comment':
     
// code relating to variables for comment templates here
     
break;
  }
 
// anything that you require for all the above, put outside the switch statement
 
return $vars; // this passes the variables back to the relevant template
}
?>

Blog Tags: DrupalThemesPHP

Comments

Add new comment