Skip to main content
Layouts are the HTML shell that wraps your pages. They contain the common structure shared across pages: doctype, head, navigation, footer, and more.

What is a Layout?

A layout is a template that defines the outer structure of your pages. Instead of repeating the HTML boilerplate in every page, you define it once in a layout. Without layouts - every page repeats this:
With layouts - define once, pages fill in the content:

Directory Structure

Layouts live in the layouts/ subdirectory:

Creating a Layout

Basic Layout

Key point: {{.Content}} is where the rendered page content is inserted.

Page Template

Pages simply provide content - no layout wrapper needed:

How It Works

When you render a page:
The engine:
  1. Renders pages/home.html with your data
  2. Puts the result in .Content
  3. Renders layouts/default.html with .Content set

Setting the Default Layout

Configure the default layout in your engine:

Multiple Layouts

Create different layouts for different sections of your site.

Admin Layout

Using a Different Layout

Override the default layout when rendering:

Minimal Layout

For simple pages that don’t need full navigation:

No Layout

For AJAX responses, partial HTML, or API endpoints that return HTML fragments:
This is useful for:
  • HTMX partial updates
  • AJAX content loading
  • Email templates (that define their own complete HTML)

Layout Data Access

Layouts have access to all the same data as pages:

Common Patterns

Dynamic Navigation

Highlight the current page:
Or pass the current path:

Flash Messages

Display flash messages from sessions:

Page-Specific Body Classes

Meta Tags

Conditional Scripts

Best Practices

1. Keep Layouts Focused

Each layout should serve a clear purpose:
  • default.html - Main public pages
  • admin.html - Admin panel
  • auth.html - Login/signup pages
  • email.html - Email templates

2. Pass Common Data via Middleware

Instead of passing the same data in every handler, use middleware:

3. Use Meaningful Names

4. Don’t Overcomplicate

Start simple. Most sites only need 2-3 layouts:
  • Main layout for public pages
  • Admin layout for backend
  • Minimal layout for auth pages

5. Test All Layouts

Make sure every layout works with your data: