{# Renders a dropdown menu component. @param id {string} [optional] - Unique identifier for the dropdown component. @param trigger {string} [optional] - HTML content for the button that triggers the dropdown. @param items {array} [optional] - Array of menu items for the dropdown. @param main_attrs {object} [optional] - Additional HTML attributes for the main container div. @param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger button. @param popover_attrs {object} [optional] - Additional HTML attributes for the dropdown content div. #} {% macro dropdown_menu( trigger, id=None, items=None, main_attrs={}, trigger_attrs={}, popover_attrs={}, menu_attrs={} ) %} {% set id = id or ("dropdown-menu-" + (range(100000, 999999) | random | string)) %} {% endmacro %} {# Renders dropdown menu items recursively. @param items {array} - The array of items to render. @param parent_id_prefix {string} [optional] - Prefix for generating element IDs. #} {% macro render_dropdown_items(items, parent_id_prefix="items") %} {% for item in items %} {% set item_id = parent_id_prefix ~ "-" ~ loop.index %} {% if item.type == "group" %} {% set group_label_id = item.id if item.id else "group-label-" + item_id %}
{{ item.label }}
{{ render_dropdown_items(item['items'], item_id) if item['items'] }}
{% elif item.type == "separator" %}
{% elif item.type == "item" or not item.type %} {% if item.url %} {% if item.icon %}{{ item.icon | safe }}{% endif %} {{ item.label | safe }} {% else %} {% endif %} {% endif %} {% endfor %} {% endmacro %}