From: digitalcraftsman <digitalcraftsman@users.noreply.github.com>
Date: Sat, 27 Feb 2016 15:51:07 +0000 (+0100)
Subject: Add template function slice
X-Git-Tag: v0.16~307
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=c1f8b188f7c05cd38e7bac71998fffd0485dd5f5;p=brevno-suite%2Fhugo

Add template function slice
---

diff --git a/docs/content/templates/functions.md b/docs/content/templates/functions.md
index 67537c70..146ab8e9 100644
--- a/docs/content/templates/functions.md
+++ b/docs/content/templates/functions.md
@@ -75,6 +75,18 @@ or Create a map on the fly to pass into
     
 
 
+### 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.
 
diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go
index 0f71fed1..ba634929 100644
--- a/tpl/template_funcs.go
+++ b/tpl/template_funcs.go
@@ -105,6 +105,11 @@ func dictionary(values ...interface{}) (map[string]interface{}, error) {
 	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 @@ func init() {
 		"seq":          helpers.Seq,
 		"shuffle":      shuffle,
 		"singularize":  singularize,
+		"slice":        slice,
 		"slicestr":     slicestr,
 		"sort":         sortSeq,
 		"split":        split,