gohugoio/hugo · error
need at least 2 arguments to append
Error message
need at least 2 arguments to append
What it means
Append (append.go:31) takes variadic args where the LAST arg is the destination slice and the rest are elements to add. With fewer than 2 args there is no element+slice pair, so the call is rejected at line 33 before any reflection. The message is an explicit arity guard.
Solutions
- Pass at least one element plus the destination slice: {{ $pages | append .Page }}
- To merge two slices of the same element type, pass both: {{ append $morePages $pages }}
- When piping, always provide the element(s) after the pipe target
Example fix
// before
{{ $pages | append }}
// after
{{ $pages | append .Page }} Defensive patterns
Strategy: validation
Validate before calling
{{/* ensure at least one element plus the slice before appending */}}
{{ if and $elem $pages }}
{{ $pages = $pages | append $elem }}
{{ end }} Prevention
- Always pass the destination slice as the last positional arg and at least one element before it
- When piping, remember the pipe target is the final arg, so you still need the element(s)
- Treat append as needing (element..., slice) not (slice) alone
When it happens
Trigger: Calling {{ append .Pages }} with one arg, or {{ $pages | append }} where the pipe supplies the only argument (len(args) < 2). The pipe target becomes the sole positional arg.
Common situations: Refactoring a template and dropping the appended value; piping a slice into append but forgetting to pass the element to add; calling append intending to clone a single slice.
Related errors
- invalid dictionary call
- both limit and seq must be provided
- can't find function
- complement needs at least two arguments
- invalid number of arguments to Seq
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/41fe87fc4e5117ee.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/collections/append.go:33
import (
"errors"
"github.com/gohugoio/hugo/common/collections"
)
// 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 }}
//
// 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 }}
func (ns *Namespace) Append(args ...any) (any, error) {
if len(args) < 2 {
return nil, errors.New("need at least 2 arguments to append")
}
to := args[len(args)-1]
from := args[:len(args)-1]
return collections.Append(to, from...)
}
View on GitHub (pinned to 52c9bd7908)