{"record":{"id":"cb2e7086be8d31b0","repo":"gohugoio/hugo","slug":"template-no-template-q-associated-with-template","errorCode":null,"errorMessage":"template: no template %q associated with template %q","messagePattern":"template: no template %q associated with template %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/internal/go_templates/texttemplate/exec.go","lineNumber":191,"sourceCode":"\t\tcase ExecError:\n\t\t\t*errp = err // Keep the wrapper.\n\t\tdefault:\n\t\t\tpanic(e)\n\t\t}\n\t}\n}\n\n// ExecuteTemplate applies the template associated with t that has the given name\n// to the specified data object and writes the output to wr.\n// If an error occurs executing the template or writing its output,\n// execution stops, but partial results may already have been written to\n// the output writer.\n// A template may be executed safely in parallel, although if parallel\n// executions share a Writer the output may be interleaved.\nfunc (t *Template) ExecuteTemplate(wr io.Writer, name string, data any) error {\n\ttmpl := t.Lookup(name)\n\tif tmpl == nil {\n\t\treturn fmt.Errorf(\"template: no template %q associated with template %q\", name, t.name)\n\t}\n\treturn tmpl.Execute(wr, data)\n}\n\n// Execute applies a parsed template to the specified data object,\n// and writes the output to wr.\n// If an error occurs executing the template or writing its output,\n// execution stops, but partial results may already have been written to\n// the output writer.\n// A template may be executed safely in parallel, although if parallel\n// executions share a Writer the output may be interleaved.\n//\n// If data is a [reflect.Value], the template applies to the concrete\n// value that the reflect.Value holds, as in [fmt.Print].\nfunc (t *Template) Execute(wr io.Writer, data any) error {\n\treturn t.execute(wr, data)\n}\n","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/internal/go_templates/texttemplate/exec.go#L173-L209","documentation":"Returned by text/template ExecuteTemplate when t.Lookup(name) is nil, i.e. no template with that name is associated with t. Unlike html/template, text/template ExecuteTemplate performs the lookup directly and errors if the name is unknown. The first %q is the missing name, the second %q is the parent template's own name.","triggerScenarios":"Calling (*texttemplate.Template).ExecuteTemplate(w, name, data) where name is not present among the templates associated with t (never defined, typo, or defined in a separate unassociated set).","commonSituations":"Typo in the template name; templates parsed into separate New() sets instead of one association; referencing a sub-template that a missing {{define}} was supposed to create; refactor that renamed a template without updating callers.","solutions":["Confirm name exactly matches a {{define}} name or a parsed file's base name in t's association set.","Call t.Lookup(name) before ExecuteTemplate and report available names if nil.","Ensure all sub-templates are parsed into the same set (shared via t.Parse of definitions or t.New).","Use t.DefinedTemplates() in the error message to list what is actually available."],"exampleFix":"// before\nerr := t.ExecuteTemplate(w, \"layout\", data) // error: not associated\n\n// after\nif t.Lookup(\"layout\") == nil {\n    return fmt.Errorf(\"layout not found; defined:%s\", t.DefinedTemplates())\n}\nerr := t.ExecuteTemplate(w, \"layout\", data)","handlingStrategy":"validation","validationCode":"func execText(t *template.Template, name string, w io.Writer, data any) error {\n    if t.Lookup(name) == nil {\n        return fmt.Errorf(\"no template %q; defined:%s\", name, t.DefinedTemplates())\n    }\n    return t.ExecuteTemplate(w, name, data)\n}","typeGuard":null,"tryCatchPattern":"if err := t.ExecuteTemplate(w, name, data); err != nil {\n    if strings.Contains(err.Error(), \"no template\") {\n        return t.ExecuteTemplate(w, defaultName, data)\n    }\n    return err\n}","preventionTips":["Lookup before ExecuteTemplate; report DefinedTemplates() on miss.","Associate sub-templates into one set via shared Parse.","Keep a registry of expected template names validated in tests."],"tags":["go","text-template","execute-template","lookup"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}