Gopher
FUNCTIONS

delimit

Loops through any array, slice, or map and returns a string of all the values separated by a delimiter.

Syntax

delimit COLLECTION DELIMIT LAST

delimit called in your template takes the form of

{{ delimit array/slice/map delimiter optionallastdelimiter}}

delimit loops through any array, slice, or map and returns a string of all the values separated by a delimiter, the second argument in the function call. There is an optional third parameter that lets you choose a different delimiter to go between the last two values in the loop.

To maintain a consistent output order, maps will be sorted by keys and only a slice of the values will be returned.

The examples of delimit that follow all use the same front matter:

delimit-example-front-matter.toml

+++
title: I love Delimit
tags: [ "tag1", "tag2", "tag3" ]
+++
delimit-page-tags-input.html

<p>Tags: {{ delimit .Params.tags ", " }}</p>
delimit-page-tags-output.html

<p>Tags: tag1, tag2, tag3</p>

Here is the same example but with the optional “last” delimiter:

delimit-page-tags-final-and-input.html

Tags: {{ delimit .Params.tags ", " ", and " }}
delimit-page-tags-final-and-output.html

<p>Tags: tag1, tag2, and tag3</p>