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

  • Home
  • SEARCH
  • 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 4578422
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:28:56+00:00 2026-05-21T20:28:56+00:00

I want to build a menu where I can set one link highlighted using

  • 0

I want to build a menu where I can set one link highlighted using the {% block %} tag. I have something like this in my Javascript:

<loop>
$('#a-div').append('{% block ' + variable + ' %} <a href...</a> {% endblock %}')
<endloop>

In the source, this is displayed as “{% block Home %}”

How can I make JQuery not append this as a string but as a template tag?

  • 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-21T20:28:57+00:00Added an answer on May 21, 2026 at 8:28 pm

    You can’t. At least not without making an AJAX request to a Django template. In your case, it would be slow and make unnecessary extra requests. It’s just not worth it. You can insert snippets from Django templates via jQuery by using, for example, the jQuery load function. But you can’t replace a specific {% block %} tag, because by the time jQuery runs, the template has already been processed (and references to block tags removed). But this is not a situation where you should be doing that in any case.

    Why don’t you rather highlight the menu with a CSS class? Here is my usual solution to this problem:

    1. Create a file called base_extras.py in one of your templatetags folders. If you don’t have one, create one in an appropriate folder.
    2. Inside base_extras.py, paste this code:

      from django import template
      from django.core.urlresolvers import reverse
      
      register = template.Library()
      
      @register.simple_tag
      def navactive(request, urls):
          if request.path in ( reverse(url) for url in urls.split() ):
              return "active"
          return ""
      
    3. Now, in your template, on your menus in your base template, do something like this:

      <ul class="menu">
          <li class="home {% navactive request 'home' %}"><a href="{% url home %}">Home</a></li>
          <li class="contact {% navactive request 'contact' %}"><a href="{% url contact %}">Contact</a></li>
          <li class="signup {% navactive request 'signup' %}"><a href="{% url signup %}">Sign up</a></li>
      </ul>
      
    4. This will make that the menu where your URL currently is has the active class. Then, in your CSS, just add a special class for a menu item with active to look slightly different than the other menus.

      ul.menu li.active {background: red; color: white;}
      

    And if you happen to need to change the active menu with jQuery, you can just remove the active class on all menus, and add it to the newly selected menus:

    $('ul.menu li').removeClass('active').find('.home').addClass('active'); // for example
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a temp directory that will be unique to this build.
If all tables I want to delete from have the column gamer_id can i
I want to have generalised email templates. Currently I have multiple email templates with
I'm trying to build a Chrome browser extension, that should enhance the way the
I want the messagebox to only show if the number is equal to 0.
I want to get the header of a selected tab-item of a tab-control and
Every time that I want to do a Layout, I'm getting a black layout
I'm working on a project in C# w/ XNA, and I want to reorganize
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
I'm in the process of porting some code from Linux to Mac OS X.

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.