1

1: I'm creating a data hash object and then looping through a collection of entries to store the results of various macros in it:

{% set data = {} %}
{% set people = craft.entries().section('people').all() %}

2: I'm setting a reference to each entry and then merging the content compiled into my data object:

{% for person in people %}
    {% set i = loop.index %}

    {# get and set key|values #}

     {% set data = data|merge({
        i: {
            "key": value, 
            "otherKey":  otherValue
        }
    }) %}
{% endfor %}

3: And then I'm looping through my data object for output:

{% for row in data %}
    <tr>
        <td>{{ row.key|raw }}</td>
        <td>{{ row.otherKey|raw }}</td>
    </tr>
{% endfor %}

The structure of the output at stage 3 is fine, but it's only resulting in 1 row out of 45 people entries.

What am I doing wrong at 2 please?

2

For the hash key to be dynamic, you must wrap it in parentheses:

(i): {
| improve this answer | |

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.