Architectural Blog, Modern Buildings & Casino Designs Loading...

Rendering content in node.tpl.php with Drupal 7

Rendering fields works a little differently in Drupal 7 – to our advantage!

Let’s say you wanted to print one of the fields on a node somewhere different than normal – away from the rest. In Drupal 6 this tended to be a bit of a rigmarole. Drupal 7 has made this process a lot easier.

In Drupal 7 content is rendered in nodes using the render function:

print render($content);

If we want to render a field separately, or stop a field from being rendered at all, we can use the hide function:


This stops our fields from being rendered in the print render($content); and we can now print it out wherever we like using Drupal render:

print render($content['field_image']);

It’s as easy as that, our field is now printed wherever we like and all the other fields are still printed out in $content.