views:

109

answers:

2

I have created a templatetag that loads a yaml document into a python list. In my template I have {% get_content_set %}, this dumps the raw list data. What I want to be able to do is something like

{% for items in get_content_list %} 
       <h2>{{items.title}}</h2> 
{% endfor %}`
+3  A: 

If the list is in a python variable X, then add it to the template context context['X'] = X and then you can do

{% for items in X %}
       {{ items.title }}
{% endfor %}

A template tag is designed to render output, so won't provide an iterable list for you to use. But you don't need that as the normal context + for loop are fine.

Malcolm Box
Agreed. A template tag is the wrong tool for this job.
jcdyer
A: 

Since writing complex templatetags is not an easy task (well documented though) i would take {% with %} tag source and adapt it for my needs, so it looks like

{% get_content_list as content %
{% for items in content %} 
       <h2>{{items.title}}</h2> 
{% endfor %}`
Dmitry Shevchenko
Exactly how I got it to work! Thank you!
thefab5