<p>Thank you @Robin :) but I managed to do it myself.
It works nicely :)</p>

<pre><code>{% set entries = craft.entries.section("galeria").all() %}

{% for entry in entries %}
    {% for block in entry.galeriaMatrix.all() %}
        {% switch block.type %}
            {% case "itemsGaleria" %}
                {% for image in block.fotografia %}
                    &lt;img src="{{image.url}}" alt="{{image.title}}" /&gt;
                {% endfor %}

                {{ block.titulo }}
                {{ block.texto }}
            {% default %}
        {% endswitch %}
    {% endfor %}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2019-04-10T20:11:41.460Z
2019-04-11T02:32:20.950Z
2019-04-11T02:32:20.950Z
André Castro
<p>I'm trying to loop a Matrix field that has one block containing 3 items.</p>

<pre><code>{% for block in entry.galeria.type('itemsGaleria') %}
    {% if block.titulo|length %}
        {{ block.titulo.first }}
    {% endif %}
{% endfor %}
</code></pre>

<p>But Craft always throws the error variable entry does not exist.</p>

<p>I read the Matrix section from Craft 3 docs but cannot fix this problem.</p>

<p>Any clues?</p>

CC BY-SA 4.0
2019-04-10T18:44:28.200Z
Do you define entry somewhere or are you in an entries template?
Robin Schambach
CC BY-SA 4.0
2019-04-10T18:55:11.123Z
I'm in an entries template.
André Castro
<craft3><matrix><loop>
Matrix Field - variable entry does not exist
# Matrix Field - variable entry does not exist

(Asked by: username_0 on 2019-04-10)

I'm trying to loop a Matrix field that has one block containing 3 items.
{% for block in entry.galeria.type('itemsGaleria') %}
    {% if block.titulo|length %}
        {{ block.titulo.first }}
    {% endif %}
{% endfor %}

But Craft always throws the error variable entry does not exist.
I read the Matrix section from Craft 3 docs but cannot fix this problem.
Any clues?

**Tags:** craft3, matrix, loop

> **Comments:**
> **username_1**: Do you define entry somewhere or are you in an entries template?  
> **username_0**: I'm in an entries template.  

---

## 1 answers

### Answer by username_0 on 2019-04-10. Score: 1

Thank you @Robin :) but I managed to do it myself.
It works nicely :)
{% set entries = craft.entries.section("galeria").all() %}

{% for entry in entries %}
    {% for block in entry.galeriaMatrix.all() %}
        {% switch block.type %}
            {% case "itemsGaleria" %}
                {% for image in block.fotografia %}
                    
                {% endfor %}

                {{ block.titulo }}
                {{ block.texto }}
            {% default %}
        {% endswitch %}
    {% endfor %}
{% endfor %}


---

