template or javascript

24 views
Skip to first unread message

Lorenzo Bernardi

unread,
Oct 10, 2016, 3:08:07 PM10/10/16
to django...@googlegroups.com
Hello,

I'm making a website with bootstrap and I use some menu items (in
fact nav bars) and I was wondering what is the best practice to make a
menu item highlighted when I am on the page connected with this menu
item. I mean in bootstrap the nav bar has a <li class="active"> to
highlight the fact that I'm on this page. I was wondering if I should
use django context to give the information and set in the template {% if
currentpage="home" %} class="active" {% endif %} or if I should use
some javascript code to look in which page I am and set the
class="active". Sorry if this is not the correct mailing list to send
this question but I don't know where to start looking so any information
is welcome (for exemple if there is standard practice for this kind of
things can someone give me some input?)


sincerely


L

ludovic coues

unread,
Oct 10, 2016, 3:23:51 PM10/10/16
to django...@googlegroups.com
Personally, I pass a dict named current in the context. For the home
page, the dict is {'home': 'active'} and for about, it's {'about':
'active'}. Then the link to the home page is <li class="{{
current.home }}">, the link to about is <li class="{{ current.about
}}">, etc...

It might not be the best way but it's pretty straightforward and
that's what I use when I need to highlight the current page.

I'm curious to read about how other django's user are doing it :)
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d3b54695-ecfd-afc6-26fc-0cb5adb5f31d%40lpn.cnrs.fr.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42
Reply all
Reply to author
Forward
0 new messages