print drupal field_view_field value only
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.
John Phelan
Updated on June 03, 2022Comments
-
John Phelan almost 2 years
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')); ?>
-
John Phelan over 11 yearsThanks. Thats exactly what I asked for. But I am having an issue with what I'm trying to do. Im trying to print the value of the field in a link, like such href="whatever.com/<?php echo 'field value' ?>" Is there a way to print just the value of the field not wrapped in a div? Thanks Again
-
Clive over 11 yearsYeah there's a different API function for that, I've updated the answer
-
Rajesh Vishwakarma almost 8 yearsHow can I get only single value if there are more than on value using field_view_field()