Skip to content

Commit

Permalink
Add template function slice
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalcraftsman authored and bep committed Feb 27, 2016
1 parent 9349a88 commit c1f8b18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/content/templates/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions tpl/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1558,6 +1563,7 @@ func init() {
"seq": helpers.Seq,
"shuffle": shuffle,
"singularize": singularize,
"slice": slice,
"slicestr": slicestr,
"sort": sortSeq,
"split": split,
Expand Down

0 comments on commit c1f8b18

Please sign in to comment.