diff options
| -rw-r--r-- | README.md | 24 | ||||
| -rw-r--r-- | gomplate.go | 1 |
2 files changed, 17 insertions, 8 deletions
@@ -55,6 +55,8 @@ Gomplate is an alternative that will let you process templates which also includ - [Example](#example) - [`split`](#split) - [Example](#example) + - [`splitN`](#splitn) + - [Example](#example) - [`title`](#title) - [Example](#example) - [`toLower`](#tolower) @@ -361,20 +363,26 @@ Creates a slice by splitting a string on a given delimiter. Equivalent to ##### Example -_`input.tmpl`:_ -``` -{{range split "Bart,Lisa,Maggie"}} -Hello, {{.}} -{{- end}} -``` - ```console -$ gomplate < input.tmpl +$ gomplate -i '{{range split "Bart,Lisa,Maggie" ","}}Hello, {{.}}{{end}}' Hello, Bart Hello, Lisa Hello, Maggie ``` +#### `splitN` + +Creates a slice by splitting a string on a given delimiter. The count determines +the number of substrings to return. Equivalent to [strings.SplitN](https://golang.org/pkg/strings#SplitN) + +##### Example + +```console +$ gomplate -i '{{ range splitN "foo:bar:baz" ":" 2 }}{{.}}{{end}}' +foo +bar:baz +``` + #### `title` Convert to title-case. Equivalent to [strings.Title](https://golang.org/pkg/strings/#Title) diff --git a/gomplate.go b/gomplate.go index d3755809..1f9bca24 100644 --- a/gomplate.go +++ b/gomplate.go @@ -63,6 +63,7 @@ func NewGomplate(data *Data, leftDelim, rightDelim string) *Gomplate { "hasPrefix": strings.HasPrefix, "hasSuffix": strings.HasSuffix, "split": strings.Split, + "splitN": strings.SplitN, "title": strings.Title, "toUpper": strings.ToUpper, "toLower": strings.ToLower, |
