2017-02-24 00:52:40 -06:00

1.9 KiB

title linktitle description godocref qref workson date publishdate lastmod categories tags toc signature workson hugoversion relatedfuncs deprecated draft aliases
delimit delimit `delimit` loops through any array, slice, or map and returns a string of all the values separated by a delimiter. loops through array, slice, or map and returns string of all values separated by a delimiter.
2017-02-01 2017-02-01 2017-02-01
functions
iteration
false
lists
taxonomies
terms
false false

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.

Examples of delimit use the following front matter:

{{% input file="delimit-example-front-matter.toml" nocopy="true" %}}

+++
title: I love Delimit
tags: [ "tag1", "tag2", "tag3" ]
+++

{{% /input %}}

delimit called in your template takes the form of

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

{{% input file="delimit-pages-tags.html" %}}

<p>Tags: {{ delimit .Params.tags ", " }}</p>

{{% /input %}}

{{% output "delimit-pages-tags-output.html" %}}

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

{{% /output %}}

Here is the same example but with the optional "last" delimiter:

{{% input file="delimit-page-tags-final-and.html" %}}

Tags: {{ delimit .Params.tags ", " ", and " }}

{{% /input %}}

{{% output "delimit-page-tags-final-and-output.html" %}}

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

{{% /output %}}