gohugoio/hugo · error
can't find function %s
Error message
can't find function %s
What it means
`collections.Apply` resolves the function to run by name via a template-function lookup. If no built-in template function (or namespaced function like `strings.TrimPrefix`) matches the given name, the lookup fails and Hugo returns this error with the name it couldn't find. Only Hugo template functions are eligible — not partials or methods.
Source
Thrown at tpl/collections/apply.go:44
// Apply takes an array or slice c and returns a new slice with the function fname applied over it.
func (ns *Namespace) Apply(ctx context.Context, c any, fname string, args ...any) (any, error) {
if c == nil {
return make([]any, 0), nil
}
if fname == "apply" {
return nil, errors.New("can't apply myself (no turtles allowed)")
}
seqv := reflect.ValueOf(c)
seqv, isNil := hreflect.Indirect(seqv)
if isNil {
return nil, errors.New("can't iterate over a nil value")
}
fnv, found := ns.lookupFunc(ctx, fname)
if !found {
return nil, errors.New("can't find function " + fname)
}
switch seqv.Kind() {
case reflect.Array, reflect.Slice:
r := make([]any, seqv.Len())
for i := range seqv.Len() {
vv := seqv.Index(i)
vvv, err := applyFnToThis(ctx, fnv, vv, args...)
if err != nil {
return nil, err
}
r[i] = vvv.Interface()
}
return r, nil
default:View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Fix the function name — check the Hugo functions docs for the exact name (e.g. `"upper"`, `"strings.TrimPrefix"`).
- If the logic lives in a partial or is a method, use `range` with `partial`/method calls instead of apply.
- If the alias was removed in a newer Hugo, switch to the namespaced form (e.g. `strings.Title`).
Example fix
<!-- before -->
{{ $r := apply $names "toUpper" "." }}
<!-- after -->
{{ $r := apply $names "upper" "." }} Defensive patterns
Strategy: validation
Validate before calling
{{/* function name must be a known template func, namespaced form preferred */}}
{{ $ok := slice "strings.ToUpper" "urlize" "relURL" }}
{{ $fn := "strings.ToUpper" }}
{{ if in $ok $fn }}{{ $r := apply $seq $fn "." }}{{ end }} Prevention
- Pass the exact template function name as a string, e.g. "urlize" or namespaced "strings.ToUpper"
- apply only resolves built-in template functions — not partials, variables, or Go methods
- Check spelling against the Hugo functions docs; a typo fails the whole build
- If the name comes from data/params, validate it against a whitelist before calling apply
When it happens
Trigger: Calling `{{ apply $seq "myFunc" "." }}` where `myFunc` isn't a registered template function; typos like `"uppr"`; trying to apply a partial, a page method (e.g. `.Title`), or an inline template.
Common situations: Expecting apply to work with `partial`-defined logic or custom shortcodes; using a namespace-qualified name incorrectly; version changes where a deprecated alias was removed so the old name no longer resolves.
Related errors
- can't apply myself (no turtles allowed)
- symdiff: failed to convert value: %w
- arguments to symdiff must be slices or arrays
- errWrongArgStructure
- errKeyIsEmptyString
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/1bcaf33b8c931581.json.
Report an issue: GitHub ↗.