Drupal 8 : Render a field collection item in a Twig template In Drupal 8, I have a content type which use Field Collection Module like that :


field_body (FieldCollection, repeatable)


field_image_alignment(Boolean)
field_picture (Image)
field_free_text (Long Text)



I want to theme this fields.
I overrided the field template with a file named field--node--field-body--news.html (news is the content type that contains theses fields.).

Default template is this :

{% for item in items %}
    &lt;div{{ item.attributes }}&gt;{{ item.content }}&lt;/div&gt;
{% endfor %}


And my template overrided is like that :

{% for item in items %}
  {% if item.content['#field_collection_item'].field_image_alignment.value == 1 %}
    {{ dump(item.content['#field_collection_item'].field_picture) }}
    {% endif %}
{% endfor %}


How can I render "child" fields field_pictures, field_free_text ?
I used item.content['#field_collection_item'].field_image_alignment.valueto access to the plain value but I would like to have the rendered view.

Thanks a lot.
I've just started learning Drupal and encountered the same issue.
I solved it by creating custom field formatter:

public function viewElements(FieldItemListInterface $items, $langcode)
{
  $elements = array();
  foreach ($items as $delta =&gt; $item)
    if ($item-&gt;value !== NULL)
    {
      $builder    = \Drupal::entityTypeManager()-&gt;getViewBuilder('field_collection_item');
      $elements[] = $builder-&gt;build($builder-&gt;view($item-&gt;getFieldCollectionItem()));
    }
  return $elements;
}