Gorriecoe\silverstripe-menu - using the $isCurrent variable in templates

Silverstripe Version: 4.3

Question:

I’m using the gorriecoe\silverstripe-menu add-on to manage multiple navs throughout the site I’m working on. I’ve not used this add-on before, but thought I’d give it a go. It uses the gorriecoe\silverstripe-link code, which includes an isCurrent() function.

I believe the isCurrent() function is similar to the main navigation SS comes with, and similarly I was hoping to use this to detect if the link is the current page being viewed (at least for actual pages on the site) and style it as such.

However, isCurrent doesn’t actually change anything:

<% loop MenuSet('Main') %>
    <li class="nav-item <% if $isCurrent %>active<% end_if %>">
        <a class="nav-link" href="{$LinkURL}"{$TargetAttr}{$ClassAttr}>
            {$Title} <% if $isCurrent %><span class="sr-only">(current)</span></a><% end_if %>
        </a>
    </li>
<% end_loop %>

But despite this being the active page, it outputs it like this:

<li class="nav-item ">
   <a class="nav-link" href="/about-us/">
      About Us 
   </a>
</li>

No sign of the “active” class or the “(current)” span. I’ve also tried other functions such as LinkOrCurrent() (which returns “link”).

Any pointers appreciated - as usual, probably missing something obvious :slight_smile: . It is Friday after all!