Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#431 closed enhancement (invalid)

Templates should support multiple level of lookups

Reported by: lucky@… Owned by: Adrian Holovaty
Component: Template system Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Let's say I have a dictionary with strings as keys and lists as values, like:

'dictionary': {'key1': [0, 0],
               'key2': [0.25, 0.005076142131979695],
               'key3': [0, 0],
               'key4': [0, 0]}

When I pass that to a template, I would like to access the values of the lists from within the templates, like:

{{ dictionary.key1.0 }} and {{ dictionary.key3.1 }}

Additionally, it would be nice to extend for for that:

{% for key, val in dictionary %} ... {% endfor %}

I hope you understand what I try to explain.

Change History (2)

comment:1 Changed 13 years ago by Jacob

Resolution: invalid
Status: newclosed

You already can.

{{ dictionary.key1.0 }} already works, and for the for loop you can use

{% for item in dictionary.items %} 
Key: {{ item.0 }}
Value: {{ item.1 }}
{% endfor %}

comment:2 Changed 13 years ago by lucky@…

Ups, thank you. Just for the rest of the world: the solution to access the list within the dictionary is:

{% for item in dictionary.items %} 
Key: {{ item.0 }}
Value: {{ item.1 }} - this is the whole list
 {% for value in item.1 %}
 Listvalue: {{ value }}
 {% endfor %}
{% endfor %}

Quite logical, isn't it? Sorry for bothering you.

Note: See TracTickets for help on using tickets.
Back to Top