drupal node 显示不同字段 node.tpl.php,在html.tpl.php中获取$ node变量 - Drupal 7(Get $node variable in html.tpl.p...

在html.tpl.php中获取$ node变量 - Drupal 7(Get $node variable in html.tpl.php - Drupal 7)

我试图让用户更新每个页面的标题和元描述。 我认为实现这一目的的一种简单方法是将字段添加到页面标题的“基本页面”内容类型中,然后检查该字段在html.tpl.php中是否为空,如果不是,则覆盖$ head_title与这个用户定义的值。

但是,似乎$ node变量在html.tpl.php中不可用。 任何人都可以提供一种方法让我在这个模板文件中提供这些数据,或者在发送到html.tpl.php之前更改$ head_title? 谢谢阅读。

I'm trying to allow users to update head titles and meta descriptions for each page. I thought that an easy way to achieve this would be to add a field to the 'Basic page' content type for the page title, then check if that field is not empty in html.tpl.php and if it is not, override $head_title with this user-defined value.

However, it appears that the $node variable is not available in html.tpl.php. Can anyone suggest a way for me to make this data available in this template file, or alternatively, alter $head_title before it is sent to html.tpl.php? Thanks for reading.

原文:https://stackoverflow.com/questions/6956870

更新时间:2019-06-14 04:52

最满意答案

在您的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

}

}

Taken in part from this thread that I found: http://drupal.org/node/1041768...

In your template.php, you can do the following:

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

}

}

2011-08-05

相关问答

function themename_preprocess_html(&$vars, $hook) {

if ($node = menu_get_object()) {

array_splice($vars['theme_hook_suggestions'], -1, 0, 'html__' . str_replace('-', '_', $node->type));

}

#print_r($vars['theme_hook_suggestions']); // print o

...

部分来自我发现的这个线程: 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['

...

在page.tpl.php ,你还打印<?php print $title ?> ,它打印页面的标题,而不是节点,这是节点/文章是$page是真,或者是用户名,如果你如果您在http://mysite.com/user/password页面上,请查看http://mysite.com/user页面或“申请新密码”。 这是因为如果$page为true,你不应该在node.tpl.php打印标题,因为这将打印标题两次。 当$page为false时,节点/文章标题只应打印为链接标题,因此它与节点标签或正

...

这是由于在我的页面模板中调用未定义的函数引起的。 在我开始搜索错误日志之前,这一点并不明显。 希望这可能会节省一些时间... This was being caused by calling an undefined function in my page template. This wasn't apparent until I started searching the error logs. Hope this may save someone else some time...

问题在于你正在使用-以变量名称。 -在任何PHP标识符中无效。 -是减法运算符。 您可能打算使用_ : <?php print $node->field_account_status[0]['value']; ?>

The problem is that you are using - in a variable name. - is not valid in any PHP identifier. - is the subtraction operator. You probably mean

...

您可以使用drupal_get_breadcrumb()和theme_breadcrumb()的组合自己构建面包屑,如下所示: $breadcrumb = theme('breadcrumb', array('breadcrumb' => drupal_get_breadcrumb()));

You can build the breadcrumb yourself using a combination of drupal_get_breadcrumb() and theme_breadcru

...

首先获取评论页面的URL: global $base_path;

$node_path = drupal_get_path_alias("node/" . $node->nid);

然后,将data-href属性更改为: data-href="http://mydomain.com<?php print $base_path . $node_path; ?>"

希望这有效......穆罕默德。 First get the URL of the comments page: global $b

...

block.tpl.php中的$ content只包含块的内容。 如果你想看到你当前所在页面的html,你就有了page.tpl.php,其中打印了那些区域和块。 The $content inside block.tpl.php will have only the content of the block. If you want to see the html of the page you are currently in, you have the page.tpl.php, where

...

如果你没有在你的主题中添加page.tpl.php文件,默认情况下会在modules / system / page.tpl.php中加载一个。 但绕过page.tpl.php听起来可能是通过在html.tpl.php中添加所有内容(你可以在这个模板中删除你想要的任何html而从不调用drupal渲染函数),即使这样做有点好奇,因为它显然不会影响性能,足以证明它的合理性,并且会使你的代码难以维护和阅读。 If you do not add a page.tpl.php file in your t

...

天哪,我现在为你感到难过。 它应该是$vars['theme_hook_suggestions']而不是$vars['theme_hook_suggestion'] (建议结束时的s) O M G, I feel so sorry for you now. It should be $vars['theme_hook_suggestions'] and not $vars['theme_hook_suggestion'] (the s at the end of suggestion)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值