1

I have created a custom view mode for field collections with this code:

/**
 * Implements hook_entity_info_alter().
 */
function view_modes_entity_info_alter(&$entity_info) {
  $entity_info['field_collection_item']['view modes']['myviewmode'] = array(
    'label' => t('My view mode'),
    'custom settings' => TRUE,
  );
}

And I'm trying to render the field in the node.tpl.php using the view mode with this code:

$display = array(
  'label' => 'hidden',
  'type' => 'myviewmode',
);
$output = field_view_field('node', $node, 'field_page_collection', $display);
print render($output);

But the field is rendering with the default view mode, not with the custom one I created. Is there a way to render it using the new view mode??

Thanks a lot!

2

You should read manual for field_view_field function.

  1. Do not use inside node (or any other entity) templates; use render($content[FIELD_NAME]) instead.
  2. Do not use to display all fields in an entity; use field_attach_prepare_view() and field_attach_view() instead.
  3. The field_view_value() function can be used to output a single formatted field value, without label or wrapping field markup.

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.