work52598
work52598

Hi,

I'm looking for a snippet which can check if the current tab is active on my navigation. Below is the code i'm currently running, taken mostly from a pre existing theme in which i am building my own. https://www.jakeround.com/cms/

https://paste.ofcode.org/HJmtyQBqNrveQgkC8Dqwat

daftspunk
daftspunk

Try something like this

{% set links = [
    { title: 'Home', url: 'home'|page, isActive: true }
] %}

{% macro render_menu(links) %}
    {% for item in links %}
        <li class="nav-item pl-4 pl-md-0 ml-0 ml-md-4 {{ item.isActive ? 'active' }} {{ item.sublinks ? 'dropdown' }}">
            <a
                href="{{ item.sublinks ? '#' : item.url }}"
                {% if item.sublinks %}data-toggle="dropdown"{% endif %}
                class="nav-link {{ item.sublinks ? 'dropdown-toggle' }} "
            >
                {{ item.title }}
                {% if item.sublinks %}<span class="caret"></span>{% endif %}
            </a>
            {% if item.sublinks %}
                <span class="dropdown-arrow"></span>
                <ul class="dropdown-menu {{ item.sublinks ? 'animate' }} {{ item.sublinks ? 'slideIn' }}">
                    {{ _self.render_menu(item.sublinks) }}
                </ul>
            {% endif %}
        </li>
    {% endfor %}
{% endmacro %}

{% import _self as nav %}

Last updated

1-2 of 2