{"record":{"id":"7f967aa7d4dfc50d","repo":"gohugoio/hugo","slug":"can-t-find-function-fname","errorCode":null,"errorMessage":"can't find function {fname}","messagePattern":"can't find function (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/apply.go","lineNumber":44,"sourceCode":"// Apply takes an array or slice c and returns a new slice with the function fname applied over it.\nfunc (ns *Namespace) Apply(ctx context.Context, c any, fname string, args ...any) (any, error) {\n\tif c == nil {\n\t\treturn make([]any, 0), nil\n\t}\n\n\tif fname == \"apply\" {\n\t\treturn nil, errors.New(\"can't apply myself (no turtles allowed)\")\n\t}\n\n\tseqv := reflect.ValueOf(c)\n\tseqv, isNil := hreflect.Indirect(seqv)\n\tif isNil {\n\t\treturn nil, errors.New(\"can't iterate over a nil value\")\n\t}\n\n\tfnv, found := ns.lookupFunc(ctx, fname)\n\tif !found {\n\t\treturn nil, errors.New(\"can't find function \" + fname)\n\t}\n\n\tswitch seqv.Kind() {\n\tcase reflect.Array, reflect.Slice:\n\t\tr := make([]any, seqv.Len())\n\t\tfor i := range seqv.Len() {\n\t\t\tvv := seqv.Index(i)\n\n\t\t\tvvv, err := applyFnToThis(ctx, fnv, vv, args...)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\tr[i] = vvv.Interface()\n\t\t}\n\n\t\treturn r, nil\n\tdefault:","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/apply.go#L26-L62","documentation":"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.","triggerScenarios":"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.","commonSituations":"Renamed/removed custom function or partial; using a Go-side function name that isn't registered in the template func map; case mismatch.","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"],"exampleFix":"// before\n{{ apply . \"upercase\" }}\n// after\n{{ apply . \"upper\" }}","handlingStrategy":"validation","validationCode":"{{/* restrict fname to a known-safe allowlist */}}\n{{ $allowed := slice \"upper\" \"lower\" \"string\" }}\n{{ if in $allowed $fname }}\n  {{ apply . $fname }}\n{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hugo","go-template","collections","lookup","argument-validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}