1

I have a content type with an entity reference field to select a user. Now I would like to render this field in the node template so that the field links to the user profile. I set the format of the field to "Label" in Manage Display and clicked on the gear so the label is linked to the reference entity.

But because I am printing the field programmatically it doesn't seem to work.

Here's what I do in my node template:

$field_user = field_get_items('field_collection_item', $item, 'field_user');
$field_user_output = field_view_value('field_collection_item', $item, 'field_user', $field_user[0]);
print render($field_user_output);

Does anyone know how to do this?

1
  • This may help with theming field collections, walks through a couple of different ways to accomplish the task: drupal.org/node/1155752 Jan 27, 2015 at 17:38

1 Answer 1

0

If the field is configured to display and available on the node, in node.tpl.php, you should be able to use:

print render($content['field_user']);
1
  • Thanks for your response. The problem is the entity reference field is part of some nested field collections. So my field structure looks something like this: -Field Collection --Text Field --Field Collection ---Text Field ---Entity Reference field I could probably access the field by doing print render($content['field_first_field_collection']['field_second_field_collection']['field_entity_reference'], but that seems to be an ugly solution. Would there be an easier way?
    – Smos
    Feb 5, 2013 at 8:36

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.