I think the best way to describe is problem is with an example.
{% for content in contents %}
{% for stuff in {{content}} %}
{{stuff}}
{% endfor %}
{% endfor %}
I am using google app engine webapp templates. I can't seem to use a result from the parent forloop {{content}}
as a variable for its child forloop. TemplateSyntaxError: Could not parse the remainder: '{{content}}' from '{{content}}'
Is it possible to do this? Thanks!!
1 Answer 1
You can use only content
without braces around:
{% for content in contents %}
{% for stuff in content %}
{{ stuff }}
{% endfor %}
{% endfor %}
When you are inside the first for-loop, content
exists in the context, as any other variable. Same thing for stuff
in the inner loop. Plus, blocks are generally using argument as variables, except in it is surrounded by quotes.
The {{ }}
notation can be use to only display the variable in the document.
6 Comments
for content in contents
contains the word 'math' . Would this make the inner loop {% for stuff in math %}
? It doesn't seem to be working this way.contents = ['math', 'physics']
then content
will be "math"
at the first iteration (and so the inner loop will iterate over each character, Python string are iterable), and then "physics"
at the second iteration.{% for stuff in math %}
gives me a different result than {% for stuff in content.name %}