0
votes

how should i know which variables and objects can be used directly in this file.(eg:$node,$term....) thank you.

3
For Drupal question there is drupal.stackexchange.com. - apaderno

3 Answers

1
votes

In template.php

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function phptemplate_preprocess_node(&$vars) {
  _vdump(get_defined_vars(), 1);
}

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function phptemplate_preprocess_page(&$vars) {
  _vdump(get_defined_vars(), 1);
}

And add dump function to custom module

/*
 * Custom dump function
 *
 * @param $vars
 *   An string or array containing the data.
 * @param $keys
 *   If true6 function will return keys of $vars array
 * @return a dump of $vars as drupal message.
 */
function _vdump($var, $keys = FALSE) {
  if($keys){
    drupal_set_message('<pre>' . print_r(array_keys($var), 1) . '</pre>');
  }
  else {
    drupal_set_message('<pre>' . print_r($var, 1) . '</pre>');
  }
}
0
votes

I'm guessing you're talking about creating/modifying a theme. You could use most of the standard Drupal globals. You can always use get_defined_vars to see if any other variables have been defined.

0
votes

There is no such variables in the template.php file. Do you think of $node, $terms, ... that you find on page.tpl.php or node.tpl.php ?

If yes, those variables are generated in the preprocess functions.

Modules can implements those hook to define new variables that you can directly use in those file, or template.php can also define some new variables.

Please have a look in the documentation about the preprocess