Key is a dict

Hi everyone,

This might be a silly question, but I can’t find it!
Is there a way to test whether a specific key exists in a dictionary?
If so, how do I do this?
Thanks for your reply.

One option is to use an in test and the keys() method:

{% set x = {'a':1, 'b':2, 'c':3} %}
{{ 'a' in x.keys() }}

A simple in test against the dictionary will also work for keys, but it doesn’t work for values:

{% set x = {'a':1, 'b':2, 'c':3} %}
{{ 'a' in x }}

That was it, thank you