Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Pages in multiple categories -> active menu item

Solved by johannes t View solution

Started by johannes t 8 years ago · 2 replies · 1224 views
8 years ago

Hi,

My menu looks like this: home, projects, blog, about ...

if i create a new page under projects it should also appear in blog.
This already works using collections in my blog

YAML
    content:
    items:
        - s[email protected]
        - taxonomy@:
                category: project

i use Route Overrides - Route Aliases
so e.g. in "/projects/example_project/item.md" i have "blog/example_project" as Route Alias,
so both urls

/projects/example_project

and

/blog/example_project

work.

now finally to my question:
Depending on which url i use (or how i reached the page) i want ether menu item"projects" or "blog" to be active...

i thied modifiing navigation.html.twig, but i guess thats not the right way(?)
i serched the forums but couldn't find the answer

Thanks in advance!

8 years ago

I think modifying navigation.html.twig is the right way. However such modification cause difficulty when the theme is updated and without caution you loose your modifications.

A solution is to use theme inheritance. In 2014 rhukster has written a blog post about theme inheritance.

I hope this helps.

8 years ago Solution

Thanks for your answer!
I'm already using theme inheritance, forgot to mention.

problem solved for me:
in 'navigation.html.twig' i replaced

{% set active_page = (p.active or p.activeChild) ? 'active' : '' %}

with

{% set active_page = p.slug == (grav.uri.route|split('/')[1]) ? 'active' : '' %}

it took a while until i found 'grav.uri.route' but now it works perfectly!

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by FrViPofm, 17 hours ago
1 31 4 hours ago
Themes & Styling · by stuart young, 1 month ago
3 480 1 month ago
Themes & Styling · by Sebadamus, 2 months ago
5 481 2 months ago
Themes & Styling · by martynfoster735, 2 months ago
1 460 2 months ago
Themes & Styling · by Justin Young, 2 months ago
1 490 2 months ago