Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Navigation Link with class "active"

Solved by wblz View solution

Started by wblz 9 years ago · 2 replies · 1856 views
9 years ago

Hello everyOne, first here
I have a custom theme with this code inside - navigation.html.twig

{% for link in site.links %} {% if link.url | contains('http') %} {% set domain = '' %} {% else %} {% set domain = base_url_absolute %} {% endif %} <li><a href="{{ domain }}{{ link.url }}" {% if link.url | contains('http') %}target="_blank"{% endif %}>{{ link.title }}</a></li> {% endfor %}

Inside a Grav theme default antimatter - navigation.html.twig

{% for page in pages.children.visible %} {% set current_page = (page.active or page.activeChild) ? 'active' : '' %} <li class="{{ current_page }}"> <a href="{{ page.url }}"> {% if page.header.icon %}<i class="fa fa-{{ page.header.icon }}"></i>{% endif %} {{ page.menu }} </a> </li> {% endfor %}

but this applied to my templates does not return anything...

9 years ago

It's still not clear where is the problem is, but reinstalling the new GRAV based clean with Antimatter and then uploading my ftp theme > actived all works perfectly.
Obviously the skeletons used earlier has some setting that escapes me. 🤔

If I find the setting that turns off page.active,
I'll go back and tell it if it comes back to other people. 👌

9 years ago Solution

Final 😉

TWIG
{% for page in pages.children %}

        {% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
        <li class="*{{ current_page }}">
            {% if page.home %}
            <a href="{{ page.url }}">{{ 'Home' }}</a>

                {% else %}
            <a href="{{ page.url }}">
                {% if page.header.icon %}<i class="fa fa-{{ page.header.icon }}"></i>{% endif %}
                {{ page.title }}
            </a>
            {% endif %}
        </li>

    {% endfor %}
👍 1

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 60 16 hours ago
Support · by Anna, 3 days ago
2 66 18 hours ago
Support · by Justin Young, 19 hours ago
1 33 19 hours ago
Support · by Duc , 1 week ago
2 69 6 days ago
Support · by Colin Hume, 1 week ago
2 61 6 days ago