1

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?

  • Do you define entry somewhere or are you in an entries template? – Robin Schambach Apr 10 '19 at 18:44
  • I'm in an entries template. – André Castro Apr 10 '19 at 18:55
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 %}
                    <img src="{{image.url}}" alt="{{image.title}}" />
                {% endfor %}

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.