{% from "macros/nswdesignsystem/_accordion_toggle_all.html" import toggle_all with context %} {% from "macros/nswdesignsystem/_accordion_wrapper.html" import wrapper with context %} {% from "macros/nswdesignsystem/_accordion_title.html" import title with context %} {% from "macros/nswdesignsystem/_accordion_content.html" import content with context %} {# Generic accordion. Example: {% call(idx, part) accordion(["hello", "world"]) %} {% if idx == 0 %} Hello content {% elif idx == 0 %} World content {% endif %} {% endcall %} #} {% macro accordion(length_or_headers, with_toggle_all=false, toggle_all_labels=[], open=[]) %} {% if length_or_headers is iterable %} {% set headers = length_or_headers %} {% set length = headers | length %} {% else %} {% set headers = [] %} {% set length = length_or_headers %} {% endif %}
{% if with_toggle_all %} {{ toggle_all(*toggle_all_labels) }} {% endif %} {% for idx in range(length) %} {% with inner = headers[idx] if headers else caller(idx, "title") %} {{ title(inner, open=idx in open) }} {% endwith %} {% with inner = caller(idx, "content") %} {% call content() %} {{ inner }} {% endcall %} {% endwith %} {% endfor %}
{% endmacro %} {% set wrapper = wrapper %} {% set toggle_all = toggle_all %} {% set title = title %} {% set content = content %}