{"id":"1bcaf33b8c931581","repo":"gohugoio/hugo","slug":"can-t-find-function-s","errorCode":null,"errorMessage":"can't find function %s","messagePattern":"can't find function (.+?)","errorType":"exception","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/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/apply.go#L26-L62","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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`)."],"exampleFix":"<!-- before -->\n{{ $r := apply $names \"toUpper\" \".\" }}\n<!-- after -->\n{{ $r := apply $names \"upper\" \".\" }}","handlingStrategy":"validation","validationCode":"{{/* function name must be a known template func, namespaced form preferred */}}\n{{ $ok := slice \"strings.ToUpper\" \"urlize\" \"relURL\" }}\n{{ $fn := \"strings.ToUpper\" }}\n{{ if in $ok $fn }}{{ $r := apply $seq $fn \".\" }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hugo","templates","collections","apply","function-lookup"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}