1

I create a section clientSection which I linked an matrix field like in this image: screenshot The field has two block types : clientImage which has an field clientImage and clientDescription which has an field with same name. I want to output in twig file but I don't know how exactly

{% set clients = craft.entries.section('clientSection').all() %}

{% for client in clients %}
  {# display content here #}
{% endfor %}

Thank's

1

You will need to use your Matrix field handle (which you didn't show in your question) and replace yourMatrixFieldHandle:

{% for client in clients %}
    {{ client.title }}

    {# Get all blocks related to the client entry #}
    {% for block in client.yourMatrixFieldHandle.all() %}

        {% switch block.type %}

            {% case "clientImage" %}

                {% for image in block.clientImage.all() %}
                    <img src="{{ image.getUrl() }}" alt="{{ image.title }}">
                {% endfor %}

            {% case "clientDescription" %}

                {{ block.clientDescription }}

        {% endswitch %}

    {% endfor %}

{% endfor %}

Read more about working with Matrix fields here

1
  • it works! thank you very much – Cosmin Ciolacu May 4 '20 at 14:50

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.