Sunday 15 April 2012

How to avoid iterating twice in the template with Django -



How to avoid iterating twice in the template with Django -

so lets assume have 2 div containers in view. in first div: div1, need create list of items while div2 content of items. means have through same variables twice. there way loop 1 time , somehow utilize info both divs @ once? or best practice twice illustration illustrates?

e.g.:

<div id="div1"> {% if blah1|length > 0 %} blah1 {% endif %} {% if blah2|length > 0 %} blah1 {% endif %} </div> <div id="div2> {% if blah1|length > 0 %} {{ blah1 }} {% endif %} {% if blah2|length > 0 %} {{ blah2 }} {% endif %} </div>

django

No comments:

Post a Comment