2

I'm creating a macro I'd like to reuse multiple times but the only thing that changes is the field name (matrix). Here's an example:

{% for block in entry.fieldname1 %}
<h3>{{ block.title }}</h3>

I'd like to increment this macro so I don't rewrite this code snippet over and over again but when I try and change entry.fieldname1 to a string it's no{% set string = entry.fieldname ~ 1 %} it is no longer recognized inside the for loop.

Any ideas?

3

Try using an array syntax instead of the object syntax:

{% set string = entry['fieldname' ~ 1] %}

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.