2

I'm using Drupal 7. I have a content type called Widget. One of the custom fields is field_widget_position. When I did a <?php print_r($page); ?> in the template, I can see the key-value pair of field_widget_position buried deep in the array. Is there an easier way to get a handle on field_widget_position instead of typing <?php echo $page['somefield']['somefield2']['somefield3']['etc....']['field_widget_position']; ?>?

4
$node->field_widget_position['en'][0]['value']

This is a bad solution.

The right solution is

render(field_view_field('node', $node, 'field_widget_position'));

or

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

if you don't want to print a label.

See http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way for more info.

2

I found the answer.

$node->field_widget_position['en'][0]['value']
1
  • 1
    More generically: $node->field_widget_position[$node->language][0]['value'] Apr 10 '12 at 10:10

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.