On Tue, 2008-02-12 at 09:40 +0100, Nicolas Steinmetz wrote:
> Malcolm Tredinnick a écrit :
>
> > You don't mention which of the "ul" elements is coming out empty, but I
> > guess this happens in the case where user_skill is empty. So wrap that
> > section in an {% if user_skill %} template tag (wrap it around the <ul>
> > and close it after the closing </ul>).
>
> Oups I was not clear enough :
>
> My code generates so far (a little bit simplified) :
>
> <ul>
> <li>Framework
> <ul>
> <li>Django</li>
> </ul>
> <ul>
> <li>Symfony</li>
> </ul>
> </li>
> <li>Language
> <ul>
> <li>Python</li>
> </ul>
> <ul>
> <li>PHP</li>
> </ul>
> </li>
> </ul>
>
> Where as I would like to have :
>
> <ul>
> <li>Framework
> <ul>
> <li>Django</li>
> <li>Symfony</li>
> </ul>
> </li>
> <li>Language
> <ul>
> <li>Python</li>
> <li>PHP</li>
> </ul>
> </li>
> </ul>
Ah, ok. So one solution is to twist your initial template a little bit.
Normally, whenever you insert the outer "li" element (the headings), you
really want to insert "</ul></li><li>New Heading<ul>" -- closing the
previous inner section, displaying a heading and then starting a new
inner section. The exception is the very first time around the loop when
there's no previous section to close.
So this should be close to what you're after:
<ul>
{% for item in user_skill %}
{% ifchanged %}
{% ifnotequal forloop.counter 1 %}
</ul></li>
{% endifnotequal %}
<li>{{ item.name.domain }}
<ul>
{% endifchanged %}
<li class="{{ item.level }}">...</li>
{% endfor %}
</ul>
</li>
</ul>
This will give slightly odd results if user_skill is empty, so you might
want to test that first (or maybe you know otherwise that it's always
going to contain content).
Regards,
Malcolm
--
The hardness of butter is directly proportional to the softness of the
bread.
http://www.pointy-stick.com/blog/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---