Error Using Go Templates in Archetypes

Hugo 0.24 revived archetypes, giving them the ability to use template logic. I recently began using this feature to provide more comprehensive online help in my archetypes/help.md file. Everything works great until create hits a fenced code block I don’t want parsed:

```go-html-template
<div class="btn-group{{ if eq .formactions "true" }} form-actions{{ end }}{{ with .class }} {{ . }}{{ end }}">
  {{ .body }}
</div>
```

The code block is for illustrative purposes to show users how to use a feature by explaining it in code. As a workaround I’ve removed the documentation from my help archetype.

Here’s the error I was hitting:

Error: Failed to process archetype file "help.md": template: help:547:30: executing "help" at <.formactions>: can't evaluate field formactions in type create.ArchetypeFileData

And here’s a link directly to a version of the archetype file which may be used to reproduce the problem.

Is there a way I can restore the go-html-template in Hugo 0.44 without causing errors?

No…

1 Like