简体   繁体   English

在page.tpl.php中打印$ node vars

[英]Printing $node vars in page.tpl.php

In Drupal's page.tpl.php 在Drupal的page.tpl.php中

<?php foreach($node->og_groups as $test) {dpm($test);} ?>

Gives me 给我
alt text http://img.skitch.com/20091229-ekf6xqg5dxq6cgjsgfty74umfx.jpg 替代文字http://img.skitch.com/20091229-ekf6xqg5dxq6cgjsgfty74umfx.jpg

But when I do 但是当我这样做

<?php foreach($node->og_groups as $test) {print($test);} ?>

The value doesn't show up. 该值不显示。 this is kinda frustating.. Any help is appreciated. 这有点令人沮丧。任何帮助,我们都感激不尽。

Cheers! 干杯!

As Steve Michel suggested: Try doing a view source on the rendered page; 正如史蒂夫·米歇尔Steve Michel)所建议的那样:尝试在渲染的页面上执行视图源。 it may be going to the top of the HTML and may not be visible in the browser output. 它可能会转到HTML的顶部,并且可能在浏览器输出中不可见。

Drupal first executes all code, collecting output into a variable. Drupal首先执行所有代码,将输出收集到一个变量中。 At the very end, this variable is print out. 最后,该变量被打印出来。 If you print or var_dump something in between, this will be at the very top of the output (since that's done before any of the regular content is printed). 如果您在两者之间进行打印或var_dump转换,则这将在输出的最顶部(因为这是在打印任何常规内容之前完成的)。

You even figured out the answer: use drupal_set_message (for which dpm is an abbreviation I guess?) to insert text in a nicely formatted way, somewhere in the content part of the page rather than before the tag. 您甚至可以找到答案:使用drupal_set_message(我猜是dpm的缩写吗?)以一种格式正确的方式在页面内容部分的某个地方而不是在标签之前插入文本。

If you need to print out arrays, you can use dpm(print_r($array, 1)) -- the 1 argument makes print_r return the formatted output (and pass it to dpm ) rather than printing it out directly. 如果需要打印出数组,可以使用dpm(print_r($array, 1)) - 1参数使print_r 返回格式化的输出(并将其传递给dpm ),而不是直接打印出来。

Try doing a view source on the rendered page; 尝试在渲染的页面上进行查看; it may be going to the top of the HTML and may not be visible in the browser output. 它可能会转到HTML的顶部,并且可能在浏览器输出中不可见。

您可以使用

<?php foreach($node->og_groups as $test) print_r($test) ?>

You can do this: 你可以这样做:

$node = $variables['node']; $ node = $ variables ['node'];

and then use it like a normal node. 然后像普通节点一样使用它。

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

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