Задать вопрос

Тел: +7 965 3737 888

542

Просмотров

2

Ответов

Template tag to handle navigation item selection

<p>Handles navigation item selection.</p>
<p>See the nav docstring for details.</p>

Вопрос полезен? Да0/Нет0
file_4471.py(3.7Кб)
None

Ответы (2):

Ответhomunq:04.11.2011
Ответ полезен? Да0/Нет0

for extra sugar replace lines 27-31:

    value = {'selected':'selected'}
    for part in reversed(item.split('.')):
        new_item = dict(value)
        new_item[part] = value
        value = new_item

So you can just say class="{{ nav.somesection.selected }}". You should probably change the docstring too:

or as a shortcut:

    {% block nav %}
    <ul class="nav">
        <li class="{{ nav.home.selected }}"><a href="/">Home</a></li>
        <li class="{{ nav.about.selected }}"><a href="/about/">About</a></li>
    </ul>
    {% endblock %}

Ответthe_ac:20.02.2011
Ответ полезен? Да0/Нет0

Thanks for that SmileyChris!

Whilst I can understand how to use this code, based on your documentation, I am not sure where I should paste it?

Can it just go anywhere, or does it need to go somewhere specific like [appname]/models.py?