Render a Single Field in Drupal 7

I needed a simple method to render a single field from a node object in Drupal 7, but couldn't find any good answers by searching the web.

Here is the solution I finally came to by searching the documentation:

  // Render the field named "field_image"
  $field = field_view_value('node', $node, 'field_image', $node->field_image[$node->language][0]);
  print render($field);

Comments

Thanks!!! After trying

Thanks!!!

After trying numerous examples on other forums to no avail, your example above finally worked :-)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <strike> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <css>, <drupal5>, <drupal6>, <javascript>, <mysql>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.