{% macro build_node(node, class="", style="", id="") %}
    <a href="{{ node.get_absolute_url() }}" id="{{id}}" style="{{style}}" class="list-group-item {%if request.path.startswith(node.get_absolute_url()) %}active {% else %} root-menu-item {% endif %} {{class}}">
       {{node.title}}
    </a>
    {{build_nodes(node)}}
{% endmacro %}

{% macro build_nodes(parent=None, nodes=None) %}
     {% if not parent and nodes %}
      <div class="menu">
        {% for node in nodes %}
            {{ build_node(node, id="menu-%s" % node.id) }}
        {% endfor %}
      </div>
     {% elif parent %}

    {% for node in parent.get_children(show_in_menu=True) %}
       {{
       build_node(
           node,
           id="menu-%s" % node.id,
           class="menu-child {0} menu-{1}".format(
               ("hidden-menu" if not request.path.startswith(parent.get_absolute_url()) else ""),
               parent.id
           )
       )
       }}
    {% endfor %}

     {% endif %}
{% endmacro %}