gohugoio/hugo · error
can't find function {fname}
Error message
can't find function {fname} What it means
Apply (apply.go:42-45) resolves fname via ns.lookupFunc against the template function store (and supports a 'namespace.method' split). If nothing is registered under that name, it fails fast rather than calling a zero Value.
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 52c9bd7908)
Solutions
- Verify fname against Hugo's registered template functions
- For namespaced funcs use the exact 'namespace.method' form with an exported method
- Check spelling and letter case
Example fix
// before
{{ apply . "upercase" }}
// after
{{ apply . "upper" }} Defensive patterns
Strategy: validation
Validate before calling
{{/* restrict fname to a known-safe allowlist */}}
{{ $allowed := slice "upper" "lower" "string" }}
{{ if in $allowed $fname }}
{{ apply . $fname }}
{{ end }} Prevention
- Cross-check the function name against Hugo's template func registry
- For namespaced funcs use exact 'namespace.method' with exported methods
- Avoid dynamically constructing fname from user input without an allowlist
When it happens
Trigger: Typo or wrong case in fname (e.g. "Upcase" vs "upper"); referencing a function not exposed to templates; an invalid namespace.method path where the namespace exists but the method does not.
Common situations: Renamed/removed custom function or partial; using a Go-side function name that isn't registered in the template func map; case mismatch.
Related errors
- need at least 2 arguments to append
- both limit and seq must be provided
- invalid dictionary call
- can't apply myself (no turtles allowed)
- can't iterate over a nil value
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/7f967aa7d4dfc50d.
Report an issue: GitHub.