Search code examples
templatesdrupaldrupal-7

How to programmatically render custom fields in drupal 7 page.tpl.php?


What is the solution for accessing custom fields on page.tpl.php in drupal 7? I was trying the following code but it throws a "Strict Warning only variables should be passed" error.

 print render(field_view_field('node', $node, 'field_artwork',
 array('label'=>'hidden'))); 

What is the proper way to render these fields in drupal 7? Keep in mind I have 5 fields I want to move to alternate locations in page.tpl.php, one is an image and the others are text.


Solution

  • This error occurs when you using a function call to pass its return value as parameter of another function.

    So the solution is simple:

    $field = field_view_field('node', $node, 'field_artwork',
     array('label'=>'hidden'));
    print render($field);