Using variable references to fields in a template I have a situation where Matrix within Matrix would be ideal, but instead we've ended up with a Matrix row that has pairs of fields up to a maximum of 6:

quote1
attribution1
…
quoteN
attributionN
…
quote6
attribution6


Rather than work through each pair…

{% if matrixBlock.quote1|length %} {# quote 1 stuff #} {% endif %}
…
{% if matrixBlock.quote6|length %} {# quote 6 stuff #} {% endif %}

…I thought I might be able to use a variable reference to numbers 1 to 6:

{% set quotes = [1, 2, 3, 4, 5, 6] %}

{% for n in quotes %}
    {% set nText = 'quote' ~ n %}
    {% set nCite = 'attribution' ~ n %}

    &lt;blockquote&gt;
        {{ matrixBlock.nText|md }}
        &lt;cite&gt;{{ matrixBlock.nCite }}&lt;/cite&gt;
    &lt;/blockquote&gt;
{% endfor %}


…but although {{ dump(nText) }} confirms the reference string is being parsed correctly, the string is clearly invalid as a field reference.

Is there a way to get this done to achieve a nice terse template (not the end of the world if I can't)?

I have a sense that Twig's attribute function might help, but I can't join the dots.
Figured it out:

{% for n in [1, 2, 3, 4, 5, 6] %}
    {% if attribute(matrixBlock, 'quote' ~ n)|length %}
    &lt;blockquote&gt;
        {{ attribute(matrixBlock, 'quote' ~ n) }}
        &lt;cite&gt;{{ attribute(matrixBlock, 'attribution' ~ n) }}&lt;/cite&gt;
    &lt;/blockquote&gt;
    {% endif %}
{% endfor %}