Skip to content

Commit d6117f3

Browse files
committed
text/template: add fields method
1 parent 1bd551f commit d6117f3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

text/templates/funcs.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ var Funcs = template.FuncMap{
247247
// ```
248248
"linespace": Chain(stringFunc("linespace", noError(linespace))),
249249

250+
// @api(Strings/fields) splits a string into fields separated by whitespace.
251+
//
252+
// Example:
253+
// ```tmpl
254+
// {{fields "hello world !"}}
255+
// ```
256+
//
257+
// Output:
258+
// ```
259+
// [hello world !]
260+
// ```
261+
"fields": Chain(stringFunc("fields", noError(strings.Fields))),
262+
250263
// @api(Strings/quote) returns a double-quoted string.
251264
//
252265
// Example:

0 commit comments

Comments
 (0)