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

First thing can you check manage display of your content type if the field is disabled/hidden in manage display then it is not showing in your node tpl. if this is not working then in node.tpl.php there is an $node array which provide full node object. By using this object you can print your image field like this.

$img_uri = $node->field_poster['und'][0]['uri'];
$img_url = image_style_url('image_style_name', $img_uri);
print "<img src=".$img_url."></div>";
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, privacy policy and cookie policy

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