0

I am trying to pass a dynamic value to my dictionary in my jinja template which in turn is a value. Code is as below:

"wan_link_info": [
{% for i in range(3) %}

{
    "dummy": "{{ xyz_Links.abc_{{ i }}.abc_link_type }}",
}
{% endfor %}
]

Here the dummy will have value like xyz_Links.abc_0.abc_link_type, xyz_Links.abc_1.abc_link_type, etc.

These text will return a value. Example say:

{{xyz_Links.abc_0.abc_link_type}} = "Stackoverflow"
{{xyz_Links.abc_1.abc_link_type}} = "Facebook"

When I run the above code I get this error:

**"jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got '{'"**
1
  • I was able to form the required text by using: {% set link_type = 'xyz_Links.abc_' + i|string + '.abc_link_type' %}. However when I pass link_type to "dummy" (i.e. "dummy":"{{ link_type }}") it prints the same as text and does not fetch the value. Any leads would be highly appreciated. Commented Dec 28, 2017 at 9:18

1 Answer 1

1

It looks like you are trying to fetch dict value. It can be implemented like this:

"wan_link_info": 
               [
                {% for instance in xyz_Links %}
                    {
                    "dummy": "{{ xyz_Links[instance].abc_link_type }}",
                    }
                {% endfor %}
                ]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.