Files
hugo/content/functions/delimit.md
T
Bud Parr 7fd64f19c8 Merge bp/theme-design branch containing Bud Parr's new design
It's a beautiful thing. A thousand thanks, Bud.

See PR rdwatters/hugo-docs-concept#118
2017-05-26 14:25:22 -05:00

1.9 KiB

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

title: delimit linktitle: delimit description: Loops through any array, slice, or map and returns a string of all the values separated by a delimiter. godocref: workson: [] date: 2017-02-01 publishdate: 2017-02-01 lastmod: 2017-02-01 categories: [functions] menu: docs: parent: "functions" tags: [iteration] toc: false ns: signature: ["delimit COLLECTION DELIMIT LAST"] workson: [lists,taxonomies,terms] hugoversion: relatedfuncs: [] deprecated: false draft: false aliases: []

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:

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

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

{{% /code %}}

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

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

{{% /code %}}

{{% output file="delimit-page-tags-output.html" %}}

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

{{% /output %}}

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

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

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

{{% /code %}}

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

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

{{% /output %}}