How to add custom class on the menu block using twig?
You can do this by creating template file called "menu--main.html" in your theme's template folder.

Then in place below code in that file:


{% import _self as menus %}
{{ menus.menu_links(items, attributes, 0) }}
{% macro menu_links(items, attributes, menu_level) %}
  {% import _self as menus %}
  {% if items %}
    {% if menu_level == 0 %}

  &lt;ul{{ attributes.addClass('menu', 'nav', 'navbar-nav','navbar-right') }}&gt;



    {% else %}

  &lt;ul{{ attributes.addClass('dropdown-menu') }}&gt;



    {% endif %}
    {% for item in items %}
      {% if menu_level == 0 and item.is_expanded %}

    &lt;li{{ item.attributes.addClass('expanded', 'dropdown') }}&gt;
    &lt;a href="{{ item.url }}" class="page-scroll"&gt;{{ item.title }}&lt;/a&gt;



      {% else %}
        
        {{ link(item.title, item.url) }}
      {% endif %}
      {% if item.below %}
        {{ menus.menu_links(item.below, attributes.removeClass('nav', 'navbar-nav'), menu_level + 1) }}
      {% endif %}

  &lt;/li&gt;
{% endfor %}
&lt;/ul&gt;



  {% endif %}
{% endmacro %}

This will add the class "ul"