0

I'm trying highlight a item from a menu. My menu is on my base.html. However I don’t know a way to say from a child page which item it must be highlighted. How can I accomplish that? So if the page "customers" is clicked, then the item from menu should be highlighted .

{% load i18n %}
<!DOCTYPE html>
<html lang='en'>
<!-- sidebar menu: : style can be found in sidebar.less -->
<ul class="sidebar-menu">
    <li>
    <a href="{% url core.views.dashboard %}">
        <i class="fa fa-dashboard"></i> <span>{% trans 'Dashboard' %}</span>
    </a>
</li>
<li>
    <a href="{% url customers.views.index %}">
        <i class="fa fa-th"></i> <span>{% trans 'Customers' %}</span>
    </a>
</li>
</ul>
<section>{% block content %}{% endblock %}</section>
</html>

Any idea?

Thanks in advance!

Ruben
  • 1,065
  • 5
  • 18
  • 44

1 Answers1

0

You can write a templatetags that returns or not the string 'active' depending on the link of this page and the current request.

Create a templatetags "active" for example, and add in your template:

{% with link=link %}
...
class="{% active link request %}"
...
{% endwith %}
FlogFR
  • 729
  • 7
  • 14