Shannon -jj Behrens wrote:
>>  You don't *need* recursion on templates for threaded messages like
>>your example app, that's exactly the point :)
> 
> 
> Julio, with all due respect for your programming prowess, I *like*
> recursion.  It can often make hard problems easy, even when generating
> HTML.
> 
> Anyway, I figured out how to solve the problem *using recursion*, and
> I blogged about it: 
> <http://jjinux.blogspot.com/2006/02/python-recursion-in-django-templates.html>.
>  It works, but it's nowhere near as elegant as simply being able to
> add a function to the template that I could call recursively. :-/
> 
> Best Regards,
> -jj
> 

This is ridiculous. Something like this seems a lot easier to me...

templatetags.py:

register = template.Library()

@register.inclusion_tag('comment')
def show_comment(comment):
    {'comment': comment}


comment.html:

{% load comments %}
{% comment.subject %}
{% comment.body %}
{% for child in comments.children %}
   {%show_comment child %}
{% endfor %}

page.html:

{% show_comment comment %}


The moral of the story : custom template tags aren't really an optional
bit of the framework. If you don't learn how to use at least simple_tag
and inclusion_tag, you will get annoyed quite often.

Robert

Reply via email to