Go HTML Templates
I'm working on a music scrobbler and decided to use regular degular HTML (by way of HTMX). This prompted me to dive into the stdlib's template system instead of reaching for something like Templ. Here are a view things I learned along the way.
{{ define "content" }} tag
This denotes the creation of a template. Whatever is between these tags belongs to that template. dit's important to note that you can continuously redefine templates. This comes in handy when nesting templates.
{{ template "content" .}} tag
This denotes that the template named "content" should be placed here. The . is for passing the data in the current file to the template. This will break the template when executing if the "content" template is referencing data at all if it is missing. Seems safer to just always pass it.
{{ block "content" .}} tag
This is syntactic sugar for defining and placing a template at the same time. It's the equivalent to:
{{ template "content" .}}
{{ define "content" }}
<p>Hello World</p>
{{end}}