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()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With