templ README

The project's README from github.com/a-h/templ. As one markdown file: README.md.

templ

An HTML templating language for Go that has great developer tooling.

templ

Documentation

See user documentation at https://templ.guide

Go Reference xc compatible Go Coverage Go Report Card

Tasks

version-set

Set the version of templ to the current version.

version set --template="0.3.%d"

build

Build a local version.

version set --template="0.3.%d"
cd cmd/templ
go build

install-snapshot

Build and install current version.

# Remove templ from the non-standard ~/bin/templ path
# that this command previously used.
rm -f ~/bin/templ
# Clear LSP logs.
rm -f cmd/templ/lspcmd/*.txt
# Update version.
version set --template="0.3.%d"
# Install to $GOPATH/bin or $HOME/go/bin
cd cmd/templ && go install

build-snapshot

Use goreleaser to build the command line binary using goreleaser.

goreleaser build --snapshot --clean

generate

Run templ generate using local version.

go run ./cmd/templ generate -include-version=false

test

Run Go tests.

version set --template="0.3.%d"
go run ./cmd/templ generate -include-version=false
go test ./...

test-short

Run Go tests.

version set --template="0.3.%d"
go run ./cmd/templ generate -include-version=false
go test ./... -short

test-cover

Run Go tests.

# Create test profile directories.
mkdir -p coverage/fmt
mkdir -p coverage/generate
mkdir -p coverage/version
mkdir -p coverage/unit
# Build the test binary.
go build -cover -o ./coverage/templ-cover ./cmd/templ
# Run the covered generate command.
GOCOVERDIR=coverage/fmt ./coverage/templ-cover fmt .
GOCOVERDIR=coverage/generate ./coverage/templ-cover generate -include-version=false
GOCOVERDIR=coverage/version ./coverage/templ-cover version
# Run the unit tests.
go test -cover ./... -coverpkg ./... -args -test.gocoverdir="$PWD/coverage/unit"
# Display the combined percentage.
go tool covdata percent -i=./coverage/fmt,./coverage/generate,./coverage/version,./coverage/unit
# Generate a text coverage profile for tooling to use.
go tool covdata textfmt -i=./coverage/fmt,./coverage/generate,./coverage/version,./coverage/unit -o coverage.out
# Print total
go tool cover -func coverage.out | grep total

test-cover-watch

interactive: true

gotestsum --watch -- -coverprofile=coverage.out

test-fuzz

./parser/v2/fuzz.sh
./parser/v2/goexpression/fuzz.sh

benchmark

Run benchmarks.

go run ./cmd/templ generate -include-version=false && go test ./... -bench=. -benchmem

fmt

Format all Go and templ code.

gofmt -s -w .
go run ./cmd/templ fmt .

lint

Run the lint operations that are run as part of the CI.

golangci-lint run --verbose

ensure-generated

Ensure that templ files have been generated with the local version of templ, and that those files have been added to git.

Requires: generate

git diff --exit-code

push-release-tag

Push a semantic version number to GitHub to trigger the release process.

version push --template="0.3.%d" --prefix="v"

docs-run

Run the development server.

Directory: docs

npm run start

docs-build

Build production docs site.

Directory: docs

npm run build

templ (a-h/templ)

Searching Database…

10.6K ·GitHub
What is this?templ is a templating language for writing HTML user interfaces in Go, with strong developer tooling as a headline feature.
Is templ a library I import, or a separate tool I run?Both: you write components in .templ files inside your Go project, and a command-line tool compiles them into regular Go code that your app renders server-side.
How do I get started with it?Install the templ CLI, write your first components in .templ files, and run 'templ generate' to compile them into Go code. The README links to user documentation for the full walkthrough.
Do I need to be a Go developer to use this?Yes — templ lives inside the Go ecosystem: templates compile into Go code and are formatted alongside it, so you need the Go toolchain and working Go knowledge.
Do I have to regenerate anything after I edit my templates?Yes — after changing .templ files you must run templ generate so the generated Go code stays in sync, and generated files are expected to be committed to git.
Can I run it on Windows and macOS, or is it Linux-only?It ships as a Go command-line binary, so it runs wherever Go runs — Windows, macOS, and Linux — with no special hardware or services required.
Does it work with htmx?Yes — htmx is one of the project's core topics, and since templ emits plain server-rendered HTML it pairs naturally with htmx-driven frontends.
How good is the editor support for .templ files?Good by design: the project advertises great developer tooling and ships a language server (LSP), so IDEs can provide completions and diagnostics for templ files.
Is this an established project or a new experiment?Established: templ has been developed since April 2021, holds over 10,500 GitHub stars, and uses automated CI plus goreleaser-based releases.
Creator
a-h
Size
9.8 MB
Stars
10.6K
Age
5y
Commits · 90 Days