Jinja accessing local dictionary with key as variable from loop

578 views
Skip to first unread message

thomas.lehm...@googlemail.com

unread,
Mar 24, 2014, 2:35:14 PM3/24/14
to ansible...@googlegroups.com
Hi,

the first line provides a dictionary of actors (names). The values are a list of movies.
In a loop over a movie and there over each actor I want to know in how many movies
an actor plays a role. I'm not able to access the dictionary ...

... I tried actors[actor] as well as actors.get(actor) but

                        {% set actors = page.statistic.getActorsAsDictionary() %}
                        ....
                        {{ actors.get(actor)|length }} => yells about NoneType
                        {{ actors[actor]|length }} => always 0

I tried it this way:
                        {% set actors = {"Dennis Quaid": [1]} %}
                        {{ actors[actor]|length }} => always 0

It DOES work for:
                        {% set actors = {"Dennis Quaid": [1234]} %}
                        {{ actors["Dennis Quaid"]|length }} => is "1"

What did I wrong?

Regards,
Thomas
Reply all
Reply to author
Forward
0 new messages