Just to piggyback on this since this is not a working solution and I didn’t find a lot of useful info online.
Regarding this:
{% set default_node = menu("default") %}
<ul>
{% for child in default_node.children %}
{% if child.level == 1 %}
<li><a href="{{ child.url }}">{{ child.label }}</a></li>
{% else %}
<li>
<ul>
<li><a href="{{ child.url }}">{{ child.label }}</a></li>
</ul>
</li>
{% endif %}
{% endfor %}
</ul>
This will not generate the child elements. It will yield the same results as the code from the original question (the code is basically the same with one extra condition added which does not affect the output).
Here is the code from the original question:
{% set menu = menu(module.menu) %}
{% for item in menu.children %}
<li class="{{ item.label|lower|replace(' ', '-') }}">
<a href="{{ item.url }}">{{ item.label }}</a>
</li>
{% endfor %}
However, after exploring the output of menu fuction, here is the working solution with macro included:
{% macro generateMenuMarkup(menuId) %}
{% set menu = menu(menuId) %}
{% for child in menu.children %}
<h2>{{child.label}}</h2>
<ul>
{% for node in child.children %}
<li>{{node.label}}</li>
{% endfor %}
</ul>
{% endfor %}
{% endmacro %}
Calling this macro is simple as {{ generateMenuMarkup(module.menu) }}
Calling the macro with the following menu:
Will yield following markup:
<h2>LINK-1</h2>
<ul>
<li>LINK-1-1</li>
<li>LINK-1-2</li>
<li>LINK-1-3</li>
</ul>
<h2>LINK-2</h2>
<ul>
<li>LINK-2-1</li>
<li>LINK-2-2</li>
<li>LINK-2-3</li>
</ul>
This way, you have complete control over markup regarding menus.
One additional benefit is that you can use hubl tokens directly in your menu and they will be properly rendered in your hubl markup which is not the case when you include menu directly with hubl snippet:
{% menu id=“{{ module.user_logged_in_menu }}” %}
Example:
When using macro and menu() function the content.absolute_url value (https://www.somelink.com) will be rendered.
When using hubl menu snippet, {{ content.absolute_url }} will be rendered as a simple string and value will not be inserted.
NOTE: This code will work for menus which are 1 level deep. For deeper menus more for loops will be needed.
Kind regards,
Milos