tpl: Improve template funcs GoDoc

This commit is contained in:
Bjørn Erik Pedersen
2022-12-21 13:11:08 +01:00
parent aa2c724195
commit cd1ed563a8
17 changed files with 170 additions and 163 deletions

View File

@@ -19,12 +19,15 @@ import (
"github.com/gohugoio/hugo/common/collections"
)
// Append appends the arguments up to the last one to the slice in the last argument.
// Append appends args up to the last one to the slice in the last argument.
// This construct allows template constructs like this:
// {{ $pages = $pages | append $p2 $p1 }}
//
// {{ $pages = $pages | append $p2 $p1 }}
//
// Note that with 2 arguments where both are slices of the same type,
// the first slice will be appended to the second:
// {{ $pages = $pages | append .Site.RegularPages }}
//
// {{ $pages = $pages | append .Site.RegularPages }}
func (ns *Namespace) Append(args ...any) (any, error) {
if len(args) < 2 {
return nil, errors.New("need at least 2 arguments to append")