在html.tpl.php中获取$node变量 – Drupal 7

前端之家收集整理的这篇文章主要介绍了在html.tpl.php中获取$node变量 – Drupal 7前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试允许用户更新每个页面标题和元描述.我认为实现这一目标的一种简单方法是在页面标题的“基本页面内容类型中添加一个字段,然后在html.tpl.PHP中检查该字段是否为空,如果不是,则覆盖$head_title具有此用户定义的值.

但是,似乎$node变量在html.tpl.PHP中不可用.有人可以建议我在这个模板文件中提供这些数据的方法,或者在发送到html.tpl.PHP之前改变$head_title吗?谢谢阅读.

解决方法

部分来自我找到的这个帖子: http://drupal.org/node/1041768 ……

在template.PHP中,您可以执行以下操作:

function yourtheme_preprocess_html(&$variables) {
  // If on an individual node page,add the node type to body classes.
  if ($node = menu_get_object()) {
    $variables['head_title'] = $node-> // find your cck field here
  }
}
原文链接:https://www.f2er.com/html/227815.html

猜你在找的HTML相关文章