userfrosting

How to make sidebar menu respond to URLs with parameters?


I define a URL in Slim such as:

$app->get('/dashboard/items?', ....

I then add a link to it in sidebar.twig, and sure enough, it becomes of class "active" once the link is visited.

However, if the URL contains parameters, the link no longer becomes "active".

e.g. /dashboard/items?page=3

I want the menu to recognize that we are still on the same page, and be highlighted as active. Best way to fix that?

Thank you

[UserFrosting 0.3.1]


Solution

  • UserFrosting determines which menu item to highlight by trying to match the current page URL against the URLs in the sidebar menu.

    By default, it is configured to compare the entire URL, before any # hashes. To have it disregard your query parameters as well, try having it split the current URL on both # AND ?:

    var url_head = url.href.split(/[#\?]+/, 1)[0];
    return this.href == url_head;