9

In node.tpl.php I am trying to get the raw value but the problem is that when I use render:

<?php print render($content['field_price']);?>

it does not just return field_image value but formats and outputs the whole image.

I need a way to get only the field's raw value. How can I achieve this?

7

To get the real value and not a themed one...

You can use http://api.drupal.org/api/drupal/modules!field!field.module/function/field_get_items/7

 $my_field_items = field_get_items('node', $node, 'field_my_field');

Or use Entity API module and entity_metadata_wrapper

 $node_wrapper = entity_metadata_wrapper('node', $node);
 $field_val = $node_wrapper->field_test->value();

Take a loot also at http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way

4

enable Devel module and in node-{content-type}.tpl.php use

<?php print dsm($node); ?>

on top of code.

you can see all $node fields in readable format

3

In a node template, for raw values you can access the $node object.

<?php print $node->field_price; ?>

If you need to see the structure, can do <?php print_r($node); ?>.

Also, if this is for a specific content type you should use a variation of node.tpl.php instead of node.tpl.php itself or else it will try to display fields that are non-existent on other content types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.