When rendering a menu, in the twig file, you can set a class if item.in_active_trail is set:

  {% for item in items %}
      set classes = [
        item.in_active_trail ? 'is-active',

However this class is applied to each link in the trail - so if you are on the third level, three links get this class.

Is there anything I can see OOTB on item or add to it if the menu link is the current page? I need to highlight it and not just items in the trail itself.


Have you tried to combine it with item.below? I suppose (not tested) that this could be used to only apply the class to the deepest item within the active trail. The code could look something like this:

{% for item in items %}
  {% if item.in_active_trail and not item.below %}
    set classes = [
  {% endif %}
{% endfor %}
  • Well, that would almost work - but I am using Menu Block and all children are always expanded. I am showing a two-level tree in the left sidebar. – Kevin Jan 6 '17 at 19:52
  • Again I have not tried it, but below is not the same as is_expanded, so I thought it might have worked... – Neograph734 Jan 6 '17 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.