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 9207791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:27:55+00:00 2026-06-18T00:27:55+00:00

I’m using Twitter Bootstrap and Symfony 2 with Twig. I have this for all

  • 0

I’m using Twitter Bootstrap and Symfony 2 with Twig. I have this for all my pages:

<div class="navbar navbar-inverse navbar-static-top"> 
            <div class="navbar-inner">
                <a class="brand" href="{{ path('home') }}">BudgetTracker</a>
                <ul class="nav">
                    <li class="active"><a href="{{ path('expenses') }}">Expenses</a></li>
                    <li><a href="#about">Reports</a></li>
                    <li><a href="{{ path('categories') }}">Categories</a></li>
                    <li><a href="#contact">Months</a></li>
                    <li><a href="#contact">Bank Accounts</a></li>
                    </ul>
            </div>
</div>

I don’t want to copy it on each page… The problem is that the class active attribute should be put only for the cuurent page. Is there a way to succeed without using JavaScript, only with some king of macro or include? Thank you very much in advance!


UPDATE

<div class="navbar navbar-inverse navbar-static-top"> 
    <div class="navbar-inner">
        <a class="brand" href="{{ path('home') }}">BudgetTracker</a>
        <ul class="nav">
            {% if var == 'Expenses' %}
            <li class="active"><a href="{{ path('expenses') }}">Expenses</a></li>
            {% else %}
            <li><a href="{{ path('expenses') }}">Expenses</a></li>
            {% endif %}

            {% if var == 'Reports' %}
            <li class="active"><a href="#">Reports</a></li>
            {% else %}
            <li><a href="#">Reports</a></li>
            {% endif %}

            {% if var == 'Categories' %}
            <li class="active"><a href="{{ path('categories') }}">Categories</a></li>
            {% else %}
            <li><a href="{{ path('categories') }}">Categories</a></li>
            {% endif %}

            {% if var == 'Months' %}
            <li class="active"><a href="#">Months</a></li>
            {% else %}
            <li><a href="#">Months</a></li>
            {% endif %}

           {% if var == 'Bank Accounts' %}
            <li class="active"><li><a href="#">Bank Accounts</a></li>
            {% else %}
            <li><li><a href="#">Bank Accounts</a></li>
            {% endif %} 
            </ul>
    </div>
</div>

My not very elegant try. And I call it with:

{% include 'EMBudgetTrackerBundle::navbar.html.twig' with {'var':'Categories'} %}
  • 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-06-18T00:27:57+00:00Added an answer on June 18, 2026 at 12:27 am

    It is quite simple:

    1. Define this as a single twig with
      {% block menu_block %} //your content here {% endblock %}
    2. Use your block in every page
      {% block menu_block %} {{ parent() }} {% endblock %}
    3. Make conditional statements for give your class at the current menu element. Obviously you have to pass to your twig (or retrieve from request, i.e.) the name or id of your page, to make what you’re trying to do
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.