Created
          February 18, 2020 19:32 
        
      - 
      
- 
        Save jonnymaceachern/931fc5fa020e5c5636a11fb0ce36a60b to your computer and use it in GitHub Desktop. 
Revisions
- 
        jonnymaceachern created this gist Feb 18, 2020 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ {# 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 %} <span>{{ item }}{% if items|length > 2 %},{% endif %}</span> {% else %} {# Middle items #} {% if not loop.first and not loop.last %} <span>{{ item }}, </span> {% endif %} {# Last item #} {% if loop.last %} <span> and {{ item }}</span> {% endif %} {% endif %} {% endfor %} {% endmacro %}