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-specific syntax includes:
!!!doctypes.%tag,.class, and#idelements.- Attribute lists such as
{href: "/docs"}. - Object references such as
%article[item]. - Unescaped text with
!and!=. - Rendered comments with
/and silent comments with-#. - Self-closing tags such as
%img/. - Inline interpolation with
#{value}. - Go statements with
- codeand rendered Go values with= code. - Filters:
:plain,:escaped,:preserve,:javascript, and:css. - Long statement wrapping with trailing
\or,. - Whitespace removal markers with
>and<.
Slim
Use @slim for Slim-style templates.
Slim-specific syntax includes:
doctypefor HTML5 doctypes.- Bare tag names such as
section, plus.classand#idimplicit divs. - Attribute lists such as
{href: "/docs"}. - Inline tags such as
li: a.First First Item. - Unescaped text with
|. - Rendered comments with
/and preserved HTML comments with/!. - Self-closing tags such as
img/. - Inline interpolation with
#{value}. - Go statements with
- codeand rendered Go values with= codeor== code. - Filters:
:javascriptand:css. - Long statement wrapping with trailing
\or,. - Whitespace addition markers with
>and<.
EGO
Use @ego for HTML-oriented templates with Go tags.
EGO supports:
<% ... %>for Go code blocks.<%- ... %>for Go code blocks with leading whitespace stripping.<%= ... %>for escaped output. Formatting directives such as<%= %d count %>are supported.<%! ... %>for unescaped output. Formatting directives such as<%! %v trustedValue %>are supported.<%@render ... %>,<%@children %>, and<%@slot ... %>for GoHT composition.<%# ... %>for comments.
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:
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.