Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print drupal field_view_field value only

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')); ?>
like image 405
John Phelan Avatar asked Jul 27 '12 19:07

John Phelan


1 Answers

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.

like image 193
Clive Avatar answered Oct 10 '22 15:10

Clive