Reputation: 668
Does somebody know an other way to do that with twig, because it returns me an error :/
{% for key, conversation in conversations %}
{% set lastMessage = sortedConversations.key %}
<p>{{ lastMessage }}</p>
{% endfor %}
Here is the error returned : Key "key" for array with keys "0" does not exist
Thanks !
Upvotes: 0
Views: 105
Reputation: 1296
Try this:
{% for key, conversation in conversations %}
{% set lastMessage = sortedConversations[key] %}
<p>{{ lastMessage }}</p>
{% endfor %}
Note the brackets around key
.
This way, twig should notice key as a variable and not as a simple string.
Upvotes: 1
Reputation: 5772
I'm not sure to understand, but may be you can try this:
sortedConversations[key]
instead of
sortedConversations.key
Upvotes: 2