开发者

drupal template.php

开发者 https://www.devze.com 2023-02-18 01:48 出处:网络
how should i know which variables and objects can be used directly in this file.(eg:$node,$term....) 开发者_运维知识库thank you.In template.php

how should i know which variables and objects can be used directly in this file.(eg:$node,$term....) 开发者_运维知识库thank you.


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消