navigation icon indicating copy to clipboard operation
navigation copied to clipboard

Can't get active node for Site type nodes if viewing a sub-page of the site

Open Michael-Paragonn opened this issue 1 month ago • 3 comments

Question

I have a few nodes of the "Site" type. Each is linked to their respective Craft sites in a multi-site install. For the life of me, I can't seem to get the active site recognized from a sub-page of the site.

For example, on www.example.com, the Site node linked to that site will show it as the active site, but on www.example.com/foo/bar, the Site node will not be recognized as active. This happens even if I specify true as the second parameter of getActiveNode(), as specified here.

Additional context

No response

Michael-Paragonn avatar Oct 29 '25 19:10 Michael-Paragonn

I believe this is a limitation at the moment, due to how we handle the homepage nodes of items. When dealing with the site's base URL, it's deemed the homepage, but we don't want that to be factored in as active when partial-matching regular nodes.

For now, you can make use of an event, but we'll look into it.

engram-design avatar Oct 30 '25 03:10 engram-design

Hmm, I'm far more of a front-end dev than I am familiar with the Yii side of things; I wouldn't know what to do with those events if one jumped into my lap. :p I dabbled in PHP 23 years ago, but that's about it for server-side programming.

I'm guessing it would be something with the modifyNodeActive function?

Michael-Paragonn avatar Oct 30 '25 09:10 Michael-Paragonn

It might be a bit much launching into a module (although we have a crash-course guide about it), but yeah essentially copying that code allows you to determine whether something is active or not.

I just need to review my logic with some tests, as these sorts of changes can break people's links if we don't get it right!

engram-design avatar Oct 30 '25 10:10 engram-design