M
M
Maxim Alyukov2020-08-11 00:28:14
Django
Maxim Alyukov, 2020-08-11 00:28:14

What's the best way to "catch" the current link for further visual highlighting?

Good evening.
My solution is based on catching the current slug in the view and further passing it to the template, where I iterate through the for loop.
How would you implement a method to "catch" the current page in order to extract a link to it?

# View
current_page = request.resolver_match.kwargs['slug']
context = {
    'posts': posts,
    'current_page': current_page
}

# Template
{% for tag in tags %}
    <li class="nav-item rounded mr-3 mt-3">
        <a class="nav-link link-dark {% if current_page == tag.slug %}active{% endif %}" href="{{ tag.get_absolute_url }}">{{ tag.title }}</a>
    </li>
{% endfor %}

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey Tikhonov, 2020-08-11
@tumbler

The name of the current view is in the request

V
Viktor Vsk, 2015-03-18
@hummingbird

It is unlikely that the Asset Pipeline will pick up the fotns directory by itself
Add the fonts directory to public

H
hax0r :3, 2015-03-18
@metr0

So you are not specifying the path correctly! try doing this for everyone:

src: url("../fonts/bootstrap/glyphicons-halflings-regular.eot");

D
Daulet Nogaybek, 2017-11-14
@kumkuduk

The font is not required at all. Now it is enough to include the css file.

<link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
 
<i class="fa fa-bomb fa-5x"></i>

This is enough and will work

V
vsuhachev, 2015-03-18
@vsuhachev

here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question