要输出节点内容有多种方法,自己用的两种:
1,直接打印数组内容,像这样:
print $node->title;//打印title
假设有一个字段名叫“field_caption”的长文本字段,
print $node->field_caption['und'][0]['value'];
图像字段:
print file_create_url($node->field_image['und'][0]['uri']);//函数file_create_url()转换public://之类的constants,生成实际可用的url。
另外一种方法,使用render方法,要先hide()然后才能render():
use the hide()
function to remove the field from $content, and then therender()
function to print our field somewhere else in the template.
使用hide()函数把要特别打印的字段从$content移除,然后再使用render()函数在模板文件的其他地方打印出来。
For example lets assume we have an image field called field_image,
First hide the field to prevent it printing out in
$content
:
假设我们有一个image字段叫field_image,
首先我们隐藏这个字段以阻止它从$content里被打印出来。
<?php
hide($content['field_image']);
print render($content);
?>
Then we use the render()
function and the field name to print the field somewhere else:
然后我们使用render()函数把这个字段在其他地方打印出来。
<?php
print render($content['field_image']);
?>
特别注意:在content type里设置字段显示属性的时候要注意,在不同显示类别下不同字段的可见性,一定要保证该字段在当前显示类型(比如全部显示或是“预告片”)里是显示的,否则打印不出来,程序也不报错。