Documentation
¶
Overview ¶
templ: version: v0.3.1020
Package layout provides page-level layout components including base HTML shell, containers, and structural templates.
Package layout pins the HTMX CDN scripts and their Sub-Resource Integrity hashes.
templ: version: v0.3.1020
Index ¶
Constants ¶
const ( // DefaultThemeColor is the default light-mode theme color (indigo-600) DefaultThemeColor = "#4f46e5" // DefaultDarkThemeColor is the default dark-mode theme color (indigo-950) DefaultDarkThemeColor = "#1e1b4b" )
Variables ¶
This section is empty.
Functions ¶
func Base ¶
Base renders a complete HTML5 base layout with HTMX, theme support, and meta tags Use with children... to inject page content into the body
@layout.Base(props) {
<h1>My Page</h1>
}
func Minimal ¶
func Minimal(props MinimalProps) templ.Component
Minimal renders a minimal HTML5 document without HTMX or external dependencies. Defaults Locale to "en" when empty (valid HTML lang attribute). Useful for static pages, emails, or PDF generation
@layout.Minimal(layout.MinimalProps{Title: "My Title"}) {
<h1>Hello</h1>
}
func ThemeScript ¶
ThemeScript renders the inline script that sets the dark mode class before paint. Also sets `color-scheme` so native scrollbars, form controls, and <details> match the active theme. Include this in your base template head to prevent FOUC.
func ThemeToggle ¶
ThemeToggle renders a theme toggle button with sun/moon icons. Uses role="switch" + aria-checked so screen-reader users know the active mode. Requires Tailwind CSS dark: variants and the ThemeScript in your base layout.
@layout.ThemeToggle("Toggle theme")
Types ¶
type HTMXVersion ¶ added in v0.6.0
type HTMXVersion string
HTMXVersion is a pinned HTMX main-script version. Use the exported constants (e.g. HTMXVersion2_0_10) for compile-time safety; custom versions can be constructed via HTMXVersion("x.y.z") but will fall back to the default SRI hash.
const ( // HTMXVersion2_0_10 is the htmx main-script version DefaultPageProps pins. HTMXVersion2_0_10 HTMXVersion = "2.0.10" )
type MinimalProps ¶
MinimalProps configures a minimal HTML5 document without HTMX or external dependencies
func DefaultMinimalProps ¶
func DefaultMinimalProps() MinimalProps
DefaultMinimalProps returns sensible defaults for MinimalProps
type PageProps ¶
type PageProps struct {
Title string
Description string
Locale string
OGImage string
ThemeColor string
DarkThemeColor string
CSSPath string
Favicon string
HTMXVersion HTMXVersion
HTMXUseSRI bool
// HTMXCDN overrides the CDN base URL for htmx scripts. When empty, defaults
// to "https://cdn.jsdelivr.net/npm". Set to e.g. "https://unpkg.com" to use
// a different CDN, or a self-hosted origin. Both the htmx main script and
// the response-targets extension derive their URLs from this value.
HTMXCDN string
// HTMXResponseTargets controls whether the htmx response-targets extension
// is loaded alongside htmx. Defaults to true for backward compatibility;
// set to false to skip the extra request when you don't use it.
HTMXResponseTargets bool
BodyClass string
Nonce string
HeadContent templ.Component
// SecurityHeaders controls whether security meta tags are included
SecurityHeaders bool
}
PageProps configures the base page layout
func DefaultPageProps ¶
func DefaultPageProps() PageProps
DefaultPageProps returns sensible defaults for PageProps