Add the name of the view in the context

Issue #100 closed
Former user created an issue

Why not add the name of the current view (often "self.view_name") in "self.get_context_data(**kwargs)" ?

Currently, one cannot highlight the active tab in "postman/base.html" ( "{% block postman_menu %}"). Adding this name could fix this problem.

Thanks for your attention.

Matthieu

Comments (3)

  1. Patrick Samson repo owner
    • changed status to open

    I think you should avoid making a decision in a template, based on the name of the view.

    For the case you mention, I prefer the following pattern extract (built on Bootstrap4):

    In base.html:

    <li class="nav-item {% block nav-sent %}{% endblock %}">
     <a class="nav-link" href="{% url 'postman:sent' %}">
      &raquo;&nbsp;{% trans "Sent Messages" %}
     </a>
    </li>
    

    And in sent.html only:

    ...
    {% block nav-sent %}active{% endblock %}
    ...
    
  2. Log in to comment