3

I am interested in knowing the proper way of performing the following function:

<li {% if request.path == '/' or '/<int> %}class="active"{% endif %}><a href="{{ url_for('index') }}"><i class="fa fa-home" aria-hidden="true"></i> Home</a></li>

The above does work however, if one visits a url such as '/article/3' or '/anything/', the 'active' class is triggered as well.

I had tried the following:

<li {% if request.path == '/<int> %}class="active"{% endif %}><a href="{{ url_for('index') }}"><i class="fa fa-home" aria-hidden="true"></i> Home</a></li>

The integer is representing a page number which is set to 1 by default.

Evan
  • 79
  • 1
  • 6

1 Answers1

0

I was able to perform this task the long/verbose way:

Example:

{% if request.path == '/' %}
<a href="/" class="item active">Home</a>
{% else %}
<a href="/" class="item">Home</a>
{% endif %}
Tyler Chong
  • 650
  • 2
  • 12
  • 24