{"record":{"id":"f668d11629ece2ab","repo":"gohugoio/hugo","slug":"must-provide-targetpath-the-template-data-context","errorCode":null,"errorMessage":"must provide targetPath, the template data context and a Resource object","messagePattern":"must provide targetPath, the template data context and a Resource object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/resources/resources.go","lineNumber":246,"sourceCode":"// FromString creates a Resource from a string published to the relative target path.\nfunc (ns *Namespace) FromString(targetPathIn, contentIn any) (resource.Resource, error) {\n\ttargetPath, err := cast.ToStringE(targetPathIn)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tcontent, err := cast.ToStringE(contentIn)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn ns.createClient.FromString(targetPath, content)\n}\n\n// ExecuteAsTemplate creates a Resource from a Go template, parsed and executed with\n// the given data, and published to the relative target path.\nfunc (ns *Namespace) ExecuteAsTemplate(ctx context.Context, args ...any) (resource.Resource, error) {\n\tif len(args) != 3 {\n\t\treturn nil, fmt.Errorf(\"must provide targetPath, the template data context and a Resource object\")\n\t}\n\ttargetPath, err := cast.ToStringE(args[0])\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdata := args[1]\n\n\tr, ok := args[2].(resources.ResourceTransformer)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"type %T not supported in Resource transformations\", args[2])\n\t}\n\n\treturn ns.templatesClient.ExecuteAsTemplate(ctx, r, targetPath, data)\n}\n\n// Fingerprint transforms the given Resource with a MD5 hash of the content in\n// the RelPermalink and Permalink.\nfunc (ns *Namespace) Fingerprint(args ...any) (resource.Resource, error) {","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/resources/resources.go#L228-L264","documentation":"Thrown by resources.ExecuteAsTemplate when len(args) != 3. The function signature requires exactly: targetPath (string), data context (any), and a Resource object. Any other argument count triggers this error before any type checking.","triggerScenarios":"Calling {{ resources.ExecuteAsTemplate \"path\" $resource }} (missing data) or {{ resources.ExecuteAsTemplate \"path\" . $r $extra }} (too many args). The variadic args ...any must total exactly 3.","commonSituations":"Forgetting the data context argument (most common), copying a call pattern from resources.FromString (which takes 2 args) into ExecuteAsTemplate, or accidentally passing extra options.","solutions":["Provide exactly three arguments: targetPath, data, Resource.","Pass the page/section context (.) as the data argument if unsure.","Confirm you are calling ExecuteAsTemplate and not FromString/Get.","Count arguments in the template invocation literally."],"exampleFix":"// before (missing data context):\n{{ $r := resources.ExecuteAsTemplate \"out.html\" $tmpl }}\n// after:\n{{ $r := resources.ExecuteAsTemplate \"out.html\" . $tmpl }}","handlingStrategy":"validation","validationCode":"{{ $r := resources.ExecuteAsTemplate \"out.html\" . $src }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember ExecuteAsTemplate takes exactly 3 args: targetPath, data, Resource.","Do not confuse with resources.FromString (2 args).","Always pass the current context (.) as the data argument."],"tags":["resources","executeastemplate","argument-count","template"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}