drupal7 使用(hook_preprocess_HOOK)向各个主题模版里面传递变量

函数地址:hook_preprocess_HOOK


1 首先解释下hook_preprocess_HOOK这个钩子的含义:



 自己定义的模块名字           预处理                            通过hook_theme 声明的主题


2 使用

<?php
//设置变量
function custommodule_preprocess_custom_theme_name(&$variables) {
  // Add a custom variables
  $variables['custom_var'] = 'i am a custom variable';
}


//在你的主题模版中使用变量
echo $custom_var;
或者
echo $variables['custom_var'];
 ?>

notice

】使用 函数(theme_get_registry()) 查看当前系统中有多少注冊的主题


3 举例

   custom_module_name_preprocess_node

   custom_module_name_preprocess_breadcrumb

   custom_module_name_preprocess_page

   custom_module_name_preprocess_comment


 同样功能的函数: hook_process_HOOK


原文地址:https://www.cnblogs.com/lxjshuju/p/6839320.html