Matrix Version: 6.39.2
Hello Squiz folk
Has anyone ever ran into this issue where for whatever reason you’re not using the standard menu design area but are using an Asset Lister or SSJS to render your global menu.
Then, how do you add remove the active class based on the current page path name and matching it to the href path name without having to use JavaScript.
I know there are many scenarios but would love to hear from anyone.
In this example we’re only showing the one level:
let html = '';
let nav = %globals_asset_children_link_type_1:xxx^as_asset:asset_name,asset_url,asset_type_code^empty:[]%;
html +=`<ul class="global-nav">`;
nav.forEach((asset, index) => {
if(asset.asset_type_code === 'page_standard'){
html +=`
<li class="nav-item">
<a class="nav-link <add/remove active class>" href="${asset.asset_url}">
${asset.asset_name}
</a>
</li>`;
}
});
html +=`</ul>`;
print(html);