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

jmix’s picture

precision: 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...

jmuzz’s picture

Issue summary: View changes
Status: Active » Fixed

You 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.