Skip to content

Add split util function

Choose a tag to compare

@orls orls released this 29 Nov 14:40
· 4 commits to master since this release

Add the ability to split vars by a string, useful for use with the built-in range:

{{ range $i, $v := split .MYVAR ","}} {{$i}}: {{$v}}\n{{ end }}

Given MYVAR="a,b,c", yields:

 0: a
 1: b
 2: c

Optional third arg for max-splits:

{{ range $i, $v := split .MYVAR "," 2}} {{$i}}: {{$v}}\n{{ end }}

Given MYVAR="a,b,c", yields:

 0: a
 1: b,c