1

I try to render a field collection in my node--1.tpl.php template with print render($content['field_image_teaser']) with no succes. I followed the example at http://drupal.org/node/1155752

The strange thing is, when I do a print of $content width var_dump () my field is listed:

var_dump ($content);
//...
["field_image_teaser"]=>
      array(1) {
        ["und"]=>
        array(2) {
          [0]=>
          array(1) {
            ["value"]=>
            string(1) "1"
          }
          [1]=>
          array(1) {
            ["value"]=>
            string(1) "2"
          }
        }
      }
//...  

but when I do a print of $content ['field_image_teaser'] the var_dump print out a NULL.

Edite: I'm using the current recommended version 7.x-1.0-beta4.

With the answer of Neograph734 I spot that the the dump of the field "field_image_teaser" cames not direct form "field_image_teaser". It cames from the $node Object (which is referred in every field), but I can't render that value. There is no output with: print render($node->field_image_teaser);

So is there a way to get the field collection in a renderable form to use the regular template system, or is something else wrong?

0

2 Answers 2

2

field_view_field() would probably do the trick:

$rendered = drupal_render(field_view_field('node', $node, 'field_image_teaser'));

There are other options you can pass to the function (display mode for example), so it might be worth checking out the docs to see exactly how you want to use it.

0
0

var dump can dump arrays and objects. You are assuming it is an array by using array syntax $content ['field_image_teaser'].

However you probably get presented an object. Give $content->field_image_teaser a try.

1
  • When I do a var_dump ($content->field_image_teaser); the result is unfortunately the same: "NULL".
    – crashbus
    Commented Nov 26, 2012 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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