0

I am creating a Bootstrap sub-theme and want to customize my node.tpl.php template. I have an image field with a machine name of 'field_poster'. According to the default node template:

$content: An array of node items. Use render($content) to print them all, or print a subset such as render($content['field_example']). Use hide($content['field_example']) to temporarily suppress the printing of a given element.

So, doesn't this mean I can add print render($content['field_poster']); to my node.tpl.php and it will output the image, right? Well, I've tried that and it does nothing!

How can I get my image field to render in my template?

Update

My field_poster was set to display within a Field Group in Display Settings. This changes how things work in the template. See below for my solution.

1 Answer 1

0

Ok, so here was the problem. My field_poster was nested in a Field Group under display settings. Apparently, you need to include the parent field group if you want to render child fields outside the group.

So, if my container field group is named group_fieldgroup1 I need to use the following to render my field:

<?php print render($content['group_fieldgroup1']['field_poster']); ?>

You can render the entire field group by using the following.

<?php print render($content['group_fieldgroup1']); ?>

Your Answer

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

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