I have written a custom tag. Here is the code: register = template.Library()
def bloque_menu(posicion): def items(bloque, padre): entradasMenu = bloque.menu_set.filter(padre = padre,visible=1) salida="" if entradasMenu: salida = "<ul>\n" for entrada in entradasMenu: salida += "\t<li><a href='"+entrada.enlace+"'>" + entrada.nombre + "</a></li>\n" salida += items (bloque, entrada.id) salida += "</ul>\n" return salida posicion = Posicion.objects.get(posicion=posicion) bloques = posicion.bloquemenu_set.all() for bloque in bloques: bloque.salida = items(bloque,0) return {'bloques': bloques,} register.inclusion_tag('menu/menu.html')(bloque_menu) <-- End of the code --> It's written in spanish, if someone needs a translation I'll provide it. On 17 feb, 03:15, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > 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-... > > 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 django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---