Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am wondering am I doing the right "Drupal" way in getting formatted value of node's body field. Here is my code:

$field = field_get_items('node', $node, 'body');
$body = '';
if (isset($field[0]['value'])) {
  $body = check_markup($field[0]['value'], $field[0]['format']);
share|improve this question
up vote 1 down vote accepted

The API has the field_view_value() function which essentially does the same thing as your code, except it applies all of the field/instance settings to the value so you won't need to make changes to your code if you change a field setting.

You can use it like this:

$field = field_get_items('node', $node, 'body');

$body = '';
if (isset($field[0]['value'])) {
  $body = field_view_value('node', $node, 'body', $field[0]);

Just in case you want the default HTML wrappers included with the field output, you can use field_view_field() instead.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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