Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
to render a field "view mode" (or "format") inside a node.tpl.php i use, for example:
<?php
print render(field_view_field('node', $node, 'field_myfieldname', array(
'label'=>'hidden',
'type' => 'text_summary_or_trimmed',
'settings'=>array('trim_length' => 30),
)));
?>
now i'd like to do quite the same thing, but inside a field-collection-item.tpl.php (for a field that is part of a field collection).
in my field-collection-item.tpl.php, i can render each field just like in a node;tpl.php:
<?php print render($content['field_myfieldname']); ?>
but if i try the first code above inside field-collection-item.tpl.php (to trim a field-collection field), it just doesn't work...
thanks you for helping !
Comments
Comment #1
jmix CreditAttribution: jmix commentedprecision: i'm trying to do this because i need to render two instances of the same field in the same field-collection :
first one in a 'text_summary_or_trimmed' format, and second one in a 'default' format...
Comment #2
jmuzz CreditAttribution: jmuzz commentedYou have to pass it 'field_collection_item' as the entity type instead of 'node', and make sure you are giving it a copy of the entity object. I think they can be found in $items.