Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7190643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:33:36+00:00 2026-05-28T19:33:36+00:00

I am trying to highlight a link of a currently opened category tab, here

  • 0

I am trying to highlight a link of a currently opened category tab, here is what i have already done:

globs.py

def globs(request):
    cats = Category.objects.all()
    return {'cats': cats}

views.py

def news_by_category(request, slug):
    c = Category.objects.get(slug=slug)
    news = News.objects.filter(category=c, status='p').order_by('-id')
    #news = c.news_set.all().order_by('-id')
    return object_list(
        request,
        news,
        paginate_by = 5,
        extra_context = {'c':c},
        template_name = 'news_by_category.html')

base.html #bodyclass

<body class="{% block bodyclass %}{% endblock %}">

news_by_category.html

{% block bodyclass %}{{c|cut:" "}}{% endblock %} 

base.html

<li><h4>Categories:</h4></li>
{% for i in cats %}
<li class="{{i.name|safe|cut:" "}}_li"> 
    <a href="myurl">{{ i.name }}</a>
</li> {% endfor %}

What i need to do now is to create style for every category, in category list, I could achieve this easily by styling inside a html file, but I’m not sure wether that would be proper (Would it?). I came up with some css styling,

{% for i in cats %}
body.{{ i|safe|cut:" "}} li.{{i|safe|cut:" "}}_li {
    color: red;
}

but as I can’t use django template tags inside my .css file, this wont work.

My questions:
1) How could i make this css file work for me. Any chance for a little step by step?

2) If I failed step1, how improper would it be to style those few li elements inside html file?

EDIT: /trying another way

I tried using:
base.html

{% for i in cats %}
<li class="{% ifequal 'request.get_full_path' '/k/{{ i.slug }}/' %}active{% endifequal %}">                 
<a href="#######">{{ i.name }}</a>
</li> {% endfor %}

.css

.active {{color:red;}

When i compared {{ request.get_full_path }} and /k/{{i.slug}}/ both returned same thing… but if its inside ifequal it doesnt seem to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:33:37+00:00Added an answer on May 28, 2026 at 7:33 pm

    You can create a simple class named “active” or something along those lines and add it to the current tab. Then, in your CSS you apply the active styles to that class. So you just append the active class and it’ll automatically take the active style.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just trying to get the (.portfoliocategs) category menu on this site to have a
I am currently trying to build a Java Project with several dependencies. I have
I'm trying to get JQuery to highlight an element based on the link ID
I'm trying to make a table row highlight when I click a certain link.
I'm trying to highlight image map areas with jquery hover(), I have highlighting divs
I currently have a html table (with 2 columns) and I am trying to
I'm trying to highlight the parent li element if a link is found either
I'm trying to highlight all links that do not have a href set, or
I'm trying to highlight the days on my jQuery datepicker calendar which are associated
I am trying to create a text highlight option for my website. But I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.