On Fri, 2007-02-16 at 15:16 -0800, [EMAIL PROTECTED] wrote: > Hello, I have a menu in a database, and I want to display it in an > unordered list, but I have to apply a class for every element like > <li class="theclass">Entry 1 </li> > I think that this can't be done with the filter unordered_list. > > Is there any way to use a kind of recursion to generate a menu like > this: > - Entry 0 > - Entry 1 > -Entry 1_0 > -Entry 1_0_0 > -Entry 1_1 > Entry 2 > > formatted using <ul> and <li>.
You cannot achieve exactly what you want with the builtin filter, however I can think of a couple of alternatives that would work: (1) If the class is the same for all elements in the list and you have some control over the stylesheet, put the class on the container (the "ul" element) and then your stylesheet can refer to "ul.theclass li", rather than "li.theclass". You could, alternatively, wrap all of the list item contents in a span element, but that would lead to spurious markup just for the sake of styling, which I would avoid if I could get away with annotating the container instead. (2) Copy the existing code for unordered_list and use it as the start for your own custom filter. Custom filters are not at all hard to write (see [1]) and modifying the existing code to suit your needs should not be too hard. [1] http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" 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-users?hl=en -~----------~----~----~----~------~----~------~--~---

