1

I have got a problem with an asset field in a Matrix in an _entry template. The Matrix is for a step-by-step feature. Each step has his own image. So the asset field in my Matrix calls: stepImage.

Now in my _entry template I loop over the step Matrix like:

{% for row in entry.steps %}
    ...
{% endfor %}

In this loop I try to get the asset URL like:

  {% set image = row.stepImage.first() %}
  {% if image %}
      {{image.url}}
  {% endif %}

but it does not work. If i dump it, it returns bool(false).

Do you have any ideas?

1

I'd suggest giving the Matrix templating docs a once-over.

If steps is the name of your Matrix field, then {% for row in entry.steps %} is going to be looping over each of the Matrix blocks you've defined.

Then you'd want to check for the stepImage asset field in the correct block. i.e.

{% for block in entry.steps %}
    {% if block.type == 'myBlock' %}
         {% set image = block.stepImage.one() %}
       
         {% if image %}
             {{image.url}}
         {% endif %}
    {% endif %}
{% 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.