Template Languages

GoHT templates live in .goht files and can use Haml, Slim, or EGO syntax. You can mix all three in the same file when that is useful.

Haml

Use @haml for Haml-style templates.

@haml Card(title string) {
	.card
		%h2= title
		%p Haml uses percent-prefixed tag names.
}

Haml-specific syntax includes:

Slim

Use @slim for Slim-style templates.

@slim Card(title string) {
	.card
		h2= title
		p Slim uses bare tag names.
}

Slim-specific syntax includes:

EGO

Use @ego for HTML-oriented templates with Go tags.

@ego Card(title string) {
	<div class="card">
		<h2><%= title %></h2>
		<p>EGO keeps HTML visible and uses tags for Go code.</p>
	</div>
}

EGO supports:

EGO supports these closing tags:

  • %> closes a tag normally.
  • -%> closes a tag and strips surrounding whitespace.
  • $%> closes a tag and strips one following newline.

EGO captures full Go statements between tags, so control flow must be valid Go:

@ego List(items []string) {
	<ul>
		<% for _, item := range items { %>
			<li><%= item %></li>
		<% } %>
	</ul>
}

Deprecated @goht

The original @goht directive is still supported for Haml templates, but it is deprecated. Use @haml in new code and keep @goht only when documenting or maintaining backward compatibility.