I am not able to append add a new entry into a dictionary object while using jinja2 template.
For example, here I am using jinja2 template and I have created a data variable which is a dictionary. And after checking some if condition I want to append location attribute to the data object, e.g.:
{%- set data = {
'name' : node.Name,
'id' : node.id,
}
-%}
{% if node.location !="" %}
data.append({'location': node.location})
{% endif %}
However I could not find a way to achieve this and am getting the UndefinedError:
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'append'
Has anyone faced this issue or could provide a reference to solve this?
I searched the web but could not find a solution i.e. how to achieve adding an entry to the dict object in the Jinja.
I have referred following and other web resources: