shithub: hugo

Download patch

ref: c1f8b188f7c05cd38e7bac71998fffd0485dd5f5
parent: 9349a889e2bf6262681164f41c9221a382fd57ae
author: digitalcraftsman <[email protected]>
date: Sat Feb 27 11:51:07 EST 2016

Add template function slice

--- a/docs/content/templates/functions.md
+++ b/docs/content/templates/functions.md
@@ -75,6 +75,18 @@
     
 
 
+### slice
+
+`slice` allows you to create an array (`[]interface{}`) of all arguments that you pass to this function.
+
+One use case is the concatenation of elements in combination with `delimit`:
+
+```html
+{{ delimit (slice "foo" "bar" "buzz") ", " }}
+<!-- returns the string "foo, bar, buzz" -->
+```
+
+
 ### echoParam
 Prints a parameter if it is set.
 
--- a/tpl/template_funcs.go
+++ b/tpl/template_funcs.go
@@ -105,6 +105,11 @@
 	return dict, nil
 }
 
+// slice returns a slice of all passed arguments
+func slice(args ...interface{}) []interface{} {
+	return args
+}
+
 func compareGetFloat(a interface{}, b interface{}) (float64, float64) {
 	var left, right float64
 	var leftStr, rightStr *string
@@ -1558,6 +1563,7 @@
 		"seq":          helpers.Seq,
 		"shuffle":      shuffle,
 		"singularize":  singularize,
+		"slice":        slice,
 		"slicestr":     slicestr,
 		"sort":         sortSeq,
 		"split":        split,