Get fields from a collection field in .theme I would like to know how I have to collect the field collection to get the fields it contains

$fieldItemList = $node-&gt;field_collection_gallery;
$fieldCollection = $fieldItemList[0];
$fieldCollectionItem = FieldCollectionItem::load($fieldCollection-&gt;value);
Use the following code:

$fieldCollectionItems = $node-&gt;get('field_collection_gallery');

    foreach ($fieldCollectionItems as $key =&gt; $item) {
      $fcItem = FieldCollectionItem::load($item-&gt;value);

      if ($fcItem instanceof FieldCollectionItem) {
        $fcValue = $fcItem-&gt;get('field_name')-&gt;getValue();
      }
    }


The $fcValue variable should contain the value from the field in the field collection item.

You have to replace the field_name with your own field name in the last line in the foreach() loop.