Drupal 7 -呈现存储在page.tpl.php文件.module文件函数中的变量中的HTML数据


drupal 7 - render html data stored in variable in function of .module file in page.tpl.php file

我刚刚开始使用drupal,对流程有点困惑。我在我的.module文件中的函数中有一个变量$var = "<div>Render in View</div>"。如何在page.tpl.php文件中呈现这个精确的html ?

谢谢

这可能行得通:http://api.drupal.org/api/drupal/modules%21system%21theme.api.php/function/hook_preprocess/7

function mymodule_preprocess(&$variables, $hook) {
  if ($hook == 'page') {
    $variables['my_custom_page_var'] = '<div>Render in page.tpl.php</div>';
  }
}

或者使用动态钩子名

function mymodule_preprocess_page(&$variables) {
  $variables['my_custom_page_var'] = '<div>Render in page.tpl.php</div>';
}

那么在page.tpl.php中应该可以访问$my_custom_page_var