简体   繁体   English

如何从Drupal中的视图访问节点信息

[英]How do I access node information from a view in Drupal

I have written a custom view template called "views-view-unformatted--FAQ.tpl.php. How can I access the nodes? The $rows array only holds the rendered content from the node.tpl.php template. 我已经编写了一个自定义视图模板,名为“ views-view-unformatted--FAQ.tpl.php。如何访问节点?$ rows数组仅保存来自node.tpl.php模板的渲染内容。

Bottom line is this - I want to organize the FAQ's into sections by taxonomy. 底线是这样-我想按分类法将FAQ分为几部分。

Try the $node variable. 尝试$ node变量。 If you want to see what variables you have available and have the devel module installed, you can do 如果要查看可用的变量并安装了devel模块,可以执行

<?php dpm(get_defined_vars()); ?>

inside your template. 在您的模板中。 This will display all of your variables. 这将显示所有变量。 However, if you have a view with several nodes being displayed, you will probably need to do this inside the loop that is displaying them, as they wont be defined outside the loop (at least not all of them). 但是,如果您有一个显示有多个节点的视图,则可能需要在显示它们的循环内执行此操作,因为它们不会在循环外定义(至少不是全部都定义)。

You may want to look at the Grouping Field, which can be found in the Style Options. 您可能要查看“样式”选项中的“分组字段”。 The grouping field allows you to group by any of the fields you've added (if your using a Fields Row Style view). 分组字段允许您按添加的任何字段进行分组(如果使用“字段行样式”视图)。

Otherwise if you really need access to the node object, consider switching your views Row Style to Node and then using the node template, node-node_type.tpl.php (assuming your view is of a single content type) to style each node in the view. 否则,如果您确实需要访问节点对象,请考虑将视图的“行样式”切换为“节点”,然后使用节点模板node-node_type.tpl.php(假设您的视图属于单一内容类型)来设置节点中的每个节点的样式。视图。 In this case you can also set the Build Mode in the Row Style options to Teaser so that you can differentiate between the full node view and the node view when placed in the view. 在这种情况下,您还可以将“行样式”选项中的“构建模式”设置为“预告片”,以便在放置在视图中时可以区分完整节点视图和节点视图。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM