0

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!!

Maxime Lorant
36.4k19 gold badges90 silver badges97 bronze badges
asked May 21, 2014 at 7:23

1 Answer 1

2

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.

answered May 21, 2014 at 7:28
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Maxime. I'm been trying this code an it looks promising. One question though...say the first output 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.
Yes. If 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.
I think that's the problem I'm having actually, my output is m a t h. It's like the loop is doing one character at a time, is there a way to make it so it does the entire word at once?
As I said, if you have a list of words, one loop is enough to have the whole word each time ;)
Also, I'm not sure if this is important, but content and math are in the same dictionary, but as different entries. In another words, the inner loop: {% for stuff in math %} gives me a different result than {% for stuff in content.name %}
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.