Frontend: Layouts

How to use Dracory's layout system for consistent page structures.

Layouts

The layouts package provides generic, flexible layout functions for composing pages in the frontend. These layouts are written in pure Go and function similarly to template engines like Blade (Laravel) or Django templates, but leverage the power and flexibility of Go functions.

Key Features

  • Generic & Extensible: Layouts are not tied to any specific page or feature—they can be used to compose any type of frontend page, including but not limited to dashboards.
  • Composable: Layouts can include other components, such as dashboard widgets, but this is entirely optional.
  • Pure Go: All layouts are written as Go functions, making them easy to extend and customize as needed.
  • Flexible: You can build simple or complex layouts, nest them, and adapt them to your needs.

Usage

Layouts are intended for general page composition. If you want to include dashboard-specific elements, you can, but it is not required. The layouts package is not limited to dashboards and can be used for any frontend view.

import (
    "net/http"
    "project/app/layouts"
    "github.com/gouniverse/hb"
)

func Handler(w http.ResponseWriter, r *http.Request) string {
    content := hb.Div().
        Class("my-content").
        Child(hb.H1().Text("Page Title")).
        Child(hb.P().Text("Page content goes here."))
    webpage := layouts.NewUserLayout(r, layouts.Options{
        Request: r,
        Title:   "My Page",
        Content: content,
        Scripts: []string{"// Custom JavaScript"},
    })
    return webpage.ToHTML()
}

---

## See Also: Dashboard Package

For dashboard-specific components, see the [`dashboard` package](../dashboard/dashboard.md).
Menu