print drupal field_view_field value only

一世执手 提交于 2019-12-20 19:05:21

问题


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')); ?>

回答1:


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);

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'];

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.



来源:https://stackoverflow.com/questions/11694770/print-drupal-field-view-field-value-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!