{# Loop through all items in a list, comma-separate them, but use "and" before the last item e.g. ["apples", "bananas, "carrots] becomes "apples, bananas, and carrots" #} {% macro to_sentence(items) %} {% for item in items %} {# First item #} {% if loop.first %} {{ item }}{% if items|length > 2 %},{% endif %} {% else %} {# Middle items #} {% if not loop.first and not loop.last %} {{ item }}, {% endif %} {# Last item #} {% if loop.last %} and {{ item }} {% endif %} {% endif %} {% endfor %} {% endmacro %}