enjoylife
enjoylife

Reputation: 5479

drupal template.php

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

Upvotes: 0

Views: 660

Answers (3)

dobeerman
dobeerman

Reputation: 1424

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>');
  }
}

Upvotes: 1

Haza
Haza

Reputation: 2999

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

Upvotes: 0

Thomas4019
Thomas4019

Reputation: 573

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.

Upvotes: 0

Related Questions