{"record":{"id":"3cceeefa5d064b10","repo":"gohugoio/hugo","slug":"failed-to-parse-archetype-template-s-w","errorCode":null,"errorMessage":"failed to parse archetype template: %s: %w","messagePattern":"failed to parse archetype template: (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/content_factory.go","lineNumber":77,"sourceCode":"// ApplyArchetypeTemplate templateSource to w as a template using the given Page p as the foundation for the data context.\nfunc (f ContentFactory) ApplyArchetypeTemplate(w io.Writer, p page.Page, archetypeKind, templateSource string) error {\n\tps := p.(*pageState)\n\tif archetypeKind == \"\" {\n\t\tarchetypeKind = p.Type()\n\t}\n\n\td := &archetypeFileData{\n\t\tType: archetypeKind,\n\t\tDate: htime.Now().Format(time.RFC3339),\n\t\tPage: p,\n\t\tFile: p.File(),\n\t}\n\n\ttemplateSource = f.shortcodeReplacerPre.Replace(templateSource)\n\n\ttempl, err := ps.s.TemplateStore.TextParse(\"archetype.md\", templateSource)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to parse archetype template: %s: %w\", err, err)\n\t}\n\n\tresult, err := executeToString(context.Background(), ps.s.GetTemplateStore(), templ, d)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to execute archetype template: %s: %w\", err, err)\n\t}\n\n\t_, err = io.WriteString(w, f.shortcodeReplacerPost.Replace(result))\n\n\treturn err\n}\n\nfunc (f ContentFactory) SectionFromFilename(filename string) (string, error) {\n\tfilename = filepath.Clean(filename)\n\trel, _, err := f.h.AbsProjectContentDir(filename)\n\tif err != nil {\n\t\treturn \"\", err\n\t}","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/content_factory.go#L59-L95","documentation":"Returned by ApplyArchetypeTemplate when TemplateStore.TextParse fails parsing the archetype source as a Go text/template. The archetype body (with shortcodes placeholder-swapped) had a syntax error: unbalanced delimiters, undefined function, bad pipeline, etc. The error is double-wrapped (%s and %w) for visibility.","triggerScenarios":"An archetype file contains invalid Go template syntax — e.g. {{ .Title (missing close), {{ foo }}, a function that is not registered, mismatched {{/* */}}, or a shortcode placeholder left malformed. Triggered when `hugo new` applies the archetype.","commonSituations":"Editing an archetype and introducing a typo; upgrading Hugo so a previously-tolerated construct now errors; using a template func only available in a newer/different Hugo; copying a layout snippet into an archetype that references layout-only context.","solutions":["Open the named archetype and locate the parse error line/column from the wrapped error.","Balance all {{ }} delimiters and ensure every function used is registered in Hugo's template funcMap.","Test the archetype in isolation with `hugo new --kind <name> test/x.md` after each edit.","Run with --templateMetricsHints or a Go template linter to catch undefined functions."],"exampleFix":"<!-- archetypes/post.md -->\n<!-- before -->\n+++\ntitle = \"{{ .Title\"\n+++\n<!-- after -->\n+++\ntitle = \"{{ .Title }}\"\n+++","handlingStrategy":"try-catch","validationCode":"if _, err := template.New(\"t\").Parse(archetypeSource); err != nil { /* parse error — fix before Hugo uses it */ }","typeGuard":null,"tryCatchPattern":"if err := cf.ApplyArchetypeTemplate(w, p, kind, src); err != nil {\n    if strings.Contains(err.Error(), \"failed to parse archetype template\") {\n        // show the inner parse error to locate the syntax problem\n    }\n}","preventionTips":["Parse archetypes with text/template in a lint step before committing.","Balance all delimiters; only use Hugo-registered functions.","Re-test `hugo new` after every archetype edit."],"tags":["archetype","go-template","parse-error","content-factory","hugolib"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}