Skip to content

HTMX and Templ

The WEB directory contains the web-related components and assets for the project. It leverages htmx and tmpl in Go for dynamic web content generation.

Structure

web/
│
│
├── assets/
│   └── js/
│       └── htmx.min.js     # htmx library for dynamic HTML content
│
├── base.templ              # Base template for HTML structure
├── base_templ.go           # Generated Go code for base template
├── efs.go                  # Embeds static files into the Go binary
│
├── hello.go                # Handler for the Hello Web functionality
├── hello.templ             # Template for rendering the Hello form and post data
└── hello_templ.go          # Generated Go code for hello template

Usage

  • Navigate to Project Directory:
cd my-project
  • Install Templ CLI:
go install github.com/a-h/templ/cmd/templ@latest
  • Generate Templ Function Files:
templ generate
  • Start Server:
make run

Templating

Templates are generated using the templ generate command after project creation. These templates are then compiled into Go code for efficient execution.

You can test HTMX functionality on localhost:port/web endpoint.