-1

I am developing a Django application, i had some problem,

I hope to do the following effects on Django,

<div id='cssmenu'>
<ul>
<li class='active'><a href='#'><span>Home</span></a></li>
   <li><a href='#'><span>Products</span></a></li>
   <li><a href='#'><span>Company</span></a></li>
   <li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>

Django Code,

<div id='cssmenu'>
{% for child in children %}
{% cycle 'active' 'last' as cssmenu silent %}
<li class="{{ cssmenu }}">
    <a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>
    {% if child.children %}
    <ul>
        {% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
    </ul>
    {% endif %}
</li>
{% endfor %}
</div>

Could you help me?

1 Answers1

0

That's not what cycle is for: it's for alternating between two or more alternatives. You don't want that at all.

Instead, just use the forloop attributes:

{% for child in children %}
    <li class="{% if forloop.first %}active{% elif forloop.last %}last{% endif %}">...</li>
{% endfor %}

Although I suppose you don't want the first one to always be active, but you haven't given any information about how you do want to determine where 'active' goes.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895