user11269465
user11269465

Reputation:

use if condition inside html tag using jinja tag

i made a header for my site project and it has some sections... i want to change the section color name on header using jinja but i can't the template already rendered without error but section name doesn't change and in pycharm this message shows up :Tag start is not closed

<ul class='menu'>
    <li {% if section == "dashboard" %}class="selected"{% endif %}>
      <a href="{% url 'dashboard' %}">My dashboard</a>
    </li>
    <li {% if section == "images" %}class="selected"{% endif %}>
      <a href="#">Images</a>
    </li>
    <li {% if section == "people" %}class="selected"{% endif %}>
      <a href="#">People</a>
    </li>
</ul>

Upvotes: 2

Views: 3964

Answers (2)

Tulasi
Tulasi

Reputation: 59

<ul class='menu'>
    <li class="selected">
        {% if section == "dashboard" %}
          <a href="{% url 'dashboard' %}">My dashboard</a>
        {% elif section == "images" %}
          <a href="#">Images</a>
        {% elif section == "people" %}
          <a href="#">People</a>
        {% endif %}
     </li>
 </ul>

Upvotes: 2

Meryem
Meryem

Reputation: 162

try this

{% if section == "dashboard" %}
<li class="selected">
{% else %}
<li>
{% endif %}

Upvotes: 1

Related Questions