#5713: Template language lacks means to display trees as nested structures
------------------------+---------------------------------------------------
Reporter:  NickMoffitt  |       Owner:  nobody         
  Status:  new          |   Component:  Template system
 Version:  0.96         |    Keywords:  recursion      
   Stage:  Unreviewed   |   Has_patch:  0              
------------------------+---------------------------------------------------
 I have a fairly simple need: to display tree-structured data as nested
 tags.  For my example, I'll propose that what is displayed is a list of
 links to messages in a complicated thread structure.  This is clearly a
 display logic problem, and is thus the province of the template system.
 This is also common enough of a problem that I do not feel it should be
 necessary to cobble together custom template tags to meet my needs.

 The core problem is that the templating language does not support
 recursion or even the mutable structures necessary to simulate it.  If I
 had some sort of stack that I could work with, this would be a solvable
 problem.  I understand that this is probably good for performance reasons,
 and it prevents endless loops and runaways that are probably more
 dangerous in a template than in other places.

 In the #django channel on freenode, I received many helpful proposals:
 Recursive loading of templates was one, although this was pointed out as
 being something of a performance nightmare.

 Another was to serialize my data into a traversal, with tags showing
 indent and outdent.  The trouble with this is that there's no easy way
 with the built-in tags and filters to do something like say "print as many
 </ol> tags as the value in message.outdent".  To avoid completely
 embedding HTML in my structures, I had to make the outdent properties into
 lists, so that I could iterate over them in a for loop and print a closing
 tag each time.  This is plainly bogus, but it gets the job done without
 needing any custom tags.

 I often see people ask "why are you so reluctant to write a custom tag?"
 in response to questions about the template system.  Perhaps the frequency
 of this question is a hint that the base tag and filter set need to be
 fleshed out a little better.  in the channel someone noticed that jinja
 has tackled this problem using loop recursion tags.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/5713>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to