{% set ns = namespace(left=0, right=0) %} {% for i in range(20) %} {% if uniquePathsAt(elements, 'pros-' ~ i ~ '$') | length != 0 %} {% set ns.left = i %} {% endif %} {% if uniquePathsAt(elements, 'cons-' ~ i ~ '$') | length != 0 %} {% set ns.right = i %} {% endif %} {% endfor %} {% macro item_left(index, count) -%} {% set id = 'pros-'~index %} {% if count > 1 %} {% endif %} {% if index == count %} {% endif %} {%- endmacro %} {% macro item_right(index, count) -%} {% set id = 'cons-'~index %} {% if count > 1 %} {% endif %} {% if index == count %} {% endif %} {%- endmacro %} Pros {% for i in range(ns.left) %} {{ item_left(i + 1, ns.left) }} {% endfor %} Cons {% for i in range(ns.right) %} {{ item_right(i + 1, ns.right) }} {% endfor %}