Home

GoHT GoHT

GoHT, pronounced like “Goat”, is a Haml, Slim, and EGO template engine and file generation tool for Go. It reads .goht files and generates type-safe Go code that renders HTML without runtime template parsing.

GoHT lets you write templates alongside normal Go code. Use @haml, @slim, or @ego blocks in a .goht file, then run the generator to produce HTML-rendering Go functions.

Features

  • Haml Syntax - Use compact Haml-style tags, attributes, interpolation, filters, and nesting.
  • Slim Syntax - Use terse Slim-style templates with bare tag names and indentation.
  • EGO Syntax - Use HTML-oriented templates with Go tags such as <%= value %>.
  • Type-Safe Generated Go - Compile templates to Go functions checked by the compiler.
  • Multiple Templates Per File - Keep related Haml, Slim, and EGO templates together.
  • Mixed Go and Templates - Put normal Go declarations alongside template blocks.
  • Easy Nesting - Render templates inside other templates with @render and @children.
  • Named Slots - Compose reusable layouts with named content regions.
  • IDE Support - VS Code, JetBrains IDEs, TextMate syntax support, and LSP integration.

Quick Start

Install the CLI.

$ go install github.com/stackus/goht/cmd/goht@latest

Add the library to your module.

$ go get github.com/stackus/goht

Write This

Write a template into a .goht file.

package main

@haml HelloWorld(name string) {
	%p Hello, #{name}!
}

You can also keep different template syntaxes in the same .goht file.

package main

@haml HamlGreeting(name string) {
	%p Hello from Haml, #{name}!
}

@slim SlimGreeting(name string) {
	p Hello from Slim, #{name}!
}

@ego EgoGreeting(name string) {
	<p>Hello from EGO, <%= name %>!</p>
}

Compile the template into Go code.

$ goht generate

Run This

After the generation step, you can call the generated Go function. Generated template functions return goht.Template, and Render(ctx, writer) writes to any io.Writer, including http.ResponseWriter.

package main

import (
	"context"
	"os"
)

func main() {
	HelloWorld("World").Render(context.Background(), os.Stdout)
}

To see this:

<p>Hello, World!</p>

Prefer @haml for Haml templates. The older @goht directive is still accepted for backward compatibility, but it is deprecated.