collections

collections.Delimit

用指定的分隔符连接给定切片或映射中的值,返回一个字符串。

签名
collections.Delimit SLICE|MAP DELIMITER [LAST]
返回类型
string
别名
delimit

连接切片:

{{ $s := slice "b" "a" "c" }}
{{ delimit $s ", " }} → b, a, c
{{ delimit $s ", " " and "}} → b, a and c

连接映射:

{{ $m := dict "b" 2 "a" 1 "c" 3 }}
{{ delimit $m ", " }} → 1, 2, 3
{{ delimit $m ", " " and "}} → 1, 2 and 3