I have a menu that I am display in a menu block. I am using the Block Class module to add a class to my menu block.

For example: I have a menu called "About Page Menu" that has 3 menu items. I place a the menu block for that menu and add the class "tabs" to that block.

What I would like to do is add a class to the UL element in the menu block if the menu block has a class = tabs.

For example:

# file: block--system-menu-block.html.twig
{% if attributes.hasClass('tabs') %}
  {% set content_attributes = content_attributes.addClass('newClass') %}
{% endif %}

However, the rendering of the UL element is handled in another file: menu.html.twig.

Is there a way to either:

  • set the class of the UL element from block--system-menu-block.html.twig
  • or set the class of the UL element in menu.html.twig by referencing the parent block's attributes?

This would be fairly simple with jquery:

  $('ul', $this).addclass('newClass');

Thanks in advance for your help.

Your Answer

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

Browse other questions tagged or ask your own question.