mirror of
https://github.com/gohugoio/hugo.git
synced 2025-02-17 03:24:39 +00:00
Add template function slice
This commit is contained in:
parent
9349a889e2
commit
c1f8b188f7
2 changed files with 18 additions and 0 deletions
|
@ -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
|
### echoParam
|
||||||
Prints a parameter if it is set.
|
Prints a parameter if it is set.
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,11 @@ func dictionary(values ...interface{}) (map[string]interface{}, error) {
|
||||||
return dict, nil
|
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) {
|
func compareGetFloat(a interface{}, b interface{}) (float64, float64) {
|
||||||
var left, right float64
|
var left, right float64
|
||||||
var leftStr, rightStr *string
|
var leftStr, rightStr *string
|
||||||
|
@ -1558,6 +1563,7 @@ func init() {
|
||||||
"seq": helpers.Seq,
|
"seq": helpers.Seq,
|
||||||
"shuffle": shuffle,
|
"shuffle": shuffle,
|
||||||
"singularize": singularize,
|
"singularize": singularize,
|
||||||
|
"slice": slice,
|
||||||
"slicestr": slicestr,
|
"slicestr": slicestr,
|
||||||
"sort": sortSeq,
|
"sort": sortSeq,
|
||||||
"split": split,
|
"split": split,
|
||||||
|
|
Loading…
Reference in a new issue