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

  1. Verify fname against Hugo's registered template functions
  2. For namespaced funcs use the exact 'namespace.method' form with an exported method
  3. 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

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


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/7f967aa7d4dfc50d. Report an issue: GitHub.