gohugoio/hugo · error
must provide targetPath, the template data context and a…
Error message
must provide targetPath, the template data context and a Resource object
What it means
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.
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.
Example fix
// before (missing data context):
{{ $r := resources.ExecuteAsTemplate "out.html" $tmpl }}
// after:
{{ $r := resources.ExecuteAsTemplate "out.html" . $tmpl }} Defensive patterns
Strategy: validation
Validate before calling
{{ $r := resources.ExecuteAsTemplate "out.html" . $src }} Prevention
- 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.
When it happens
Trigger: Calling {{ resources.ExecuteAsTemplate "path" $resource }} (missing data) or {{ resources.ExecuteAsTemplate "path" . $r $extra }} (too many args). The variadic args ...any must total exactly 3.
Common situations: 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.
Related errors
- Defer does not take any arguments
- expected slice of Resource objects, received %T instead
- must not provide more arguments than Resource and hash…
- must provide a Resource object
- must provide an URL and optionally an options map
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/f668d11629ece2ab.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/resources/resources.go:246
// FromString creates a Resource from a string published to the relative target path.
func (ns *Namespace) FromString(targetPathIn, contentIn any) (resource.Resource, error) {
targetPath, err := cast.ToStringE(targetPathIn)
if err != nil {
return nil, err
}
content, err := cast.ToStringE(contentIn)
if err != nil {
return nil, err
}
return ns.createClient.FromString(targetPath, content)
}
// ExecuteAsTemplate creates a Resource from a Go template, parsed and executed with
// the given data, and published to the relative target path.
func (ns *Namespace) ExecuteAsTemplate(ctx context.Context, args ...any) (resource.Resource, error) {
if len(args) != 3 {
return nil, fmt.Errorf("must provide targetPath, the template data context and a Resource object")
}
targetPath, err := cast.ToStringE(args[0])
if err != nil {
return nil, err
}
data := args[1]
r, ok := args[2].(resources.ResourceTransformer)
if !ok {
return nil, fmt.Errorf("type %T not supported in Resource transformations", args[2])
}
return ns.templatesClient.ExecuteAsTemplate(ctx, r, targetPath, data)
}
// Fingerprint transforms the given Resource with a MD5 hash of the content in
// the RelPermalink and Permalink.
func (ns *Namespace) Fingerprint(args ...any) (resource.Resource, error) {View on GitHub (pinned to 52c9bd7908)