仅打印drupal field_view_field值 [英] print drupal field_view_field value only
问题描述
我正在使用下面的代码将节点的字段打印到特定的区域,它的效果非常好。但是,这是一个我只想打印你没有标签的字段的值的实例。似乎应该很容易,但我有一点麻烦。我很感激任何帮助,因为我是新来的drupal。感谢
I'm using the code below to print the out the field of nodes to specific areas and it works great. But theres an instance where I just want to print the value you of field without the label. Seems as it should be pretty easy but I'm having a bit of trouble. I'd appreciate any help as i'm pretty new to drupal. Thanks
<?php
print drupal_render(field_view_field('node', $node, 'field_description')); ?>
推荐答案
field_view_value() code>需要一个
$ display
参数,您可以使用它来隐藏标签:
field_view_value()
takes a $display
argument that you can use to hide the label:
$display = array('label' => 'hidden');
$view = field_view_field('node', $node, 'field_description', $display);
print drupal_render($view);
如果您只想提取字段的原始值,您可以使用 field_get_items()
/ a>代替:
If you just want to extract the raw value of the field you can use field_get_items()
instead:
$items = field_get_items('node', $node, 'field_description');
$first_item = array_shift($items);
$description = $first_item['value'];
列名称( $ first_item ['whatever']
)将取决于您使用的字段类型。对于文本字段,它将是值
。在输出之前,请记住使用 check_plain()
对输入进行消毒,因为Drupal的约定是存储原始输入数据并在输出时对其进行清理。
The column name ($first_item['whatever']
) will depend on the type of field you're using. For text fields it will be value
. Remember to sanitise the input with check_plain()
before you output it as Drupal's convention is to store the raw input data and sanitise it upon output.
这篇关于仅打印drupal field_view_field值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!