{% set ns = namespace(left=0, right=0) %} {% for i in range(20) %} {% if uniquePathsAt(elements, 'left-' ~ i ~ '$') | length != 0 %} {% set ns.left = i %} {% endif %} {% if uniquePathsAt(elements, 'right-' ~ i ~ '$') | length != 0 %} {% set ns.right = i %} {% endif %} {% endfor %} {% macro row(name, index, count) -%} {% if count > 1 %} {%endif %} {% if index == count %} {%endif %} {%- endmacro %} {% macro col(name, count, offsetX, offsetY) -%} {% for index in range(count) %} {{ row(name, index+1, count) }} {% endfor %} {%- endmacro %} {{ col('left', ns.left, 18, 43) }} {{ col('right', ns.right, 342, 91) }}