想要改进这个问题?添加详细信息并阐明编辑此帖子的问题。
关闭去年。
从视图字段 - 正文模板,如何访问正在显示的节点的NID?所以,如果我有3行,我想要3个唯一的nids。谢谢。
$row->nid
想要改进这个问题?添加详细信息并阐明编辑此帖子的问题。
关闭去年。
从视图字段 - 正文模板,如何访问正在显示的节点的NID?所以,如果我有3行,我想要3个唯一的nids。谢谢。
$row->nid
From a views field--body template, how do I access the nid of the node being displayed? So if I have 3 unique rows, I want 3 unique nids. Thanks.
$row->nid
我知道这是一段时间的询问,但为了仍然搜索的好处,这里是一个解决方案。
<?php foreach ($rows as $id => $row): ?> <?php $node = node_load($view->result[$id]->nid); // do something with your node ?> <?php endforeach; ?>
I know this was asked a while ago, but for the benefit of people still searching, here is a solution.
<?php foreach ($rows as $id => $row): ?> <?php $node = node_load($view->result[$id]->nid); // do something with your node ?> <?php endforeach; ?>
使用 $result
数组。如果您正在循环通过 $rows
,则可以使用 $result[$count]->nid
获取当前对象的NID。
Use the $result
array. If you're looping through the $rows
you can get the nid of the current object with $result[$count]->nid
.
为什么不使用 print_r()
,并看看 $row
。您还可以使用Devel模块来打印出阵列。打印出数组键只使用 echo
require_once dirname(__FILE__) . '/mymodule.module'; 0
Why not use print_r()
and have a look at $row
. Also you can use devel module to print out arrays. To print out array keys only use echo
print_r(array_keys((array)$your_drupal_variable));
另一个选项是使用 require_once dirname(__FILE__) . '/mymodule.module'; 1
< / a>它将显示模板中可用的所有变量,使用它与 devel module 获得一个很好的显示:
require_once dirname(__FILE__) . '/mymodule.module'; 2
Another options is to use get_defined_vars()
which will shows all variables available in your template, use it with devel module to get a nice display:
dsm(get_defined_vars());
© 2022 it.wenda123.org All Rights Reserved. 问答之家 版权所有