render

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package render is the HTTP rendering seam for templ components. It writes components as HTML responses and supports the HTMX full-page vs. fragment pattern. It deliberately ships no layout component: the layout is supplied by the caller (the app shell is owned by the consuming application), so this package stays a thin, reusable seam.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHTMX

func IsHTMX(r *http.Request) bool

IsHTMX reports whether the request was issued by HTMX (a partial/AJAX request) rather than a full browser navigation.

func Page

func Page(
	ctx context.Context,
	w http.ResponseWriter,
	r *http.Request,
	layout func(templ.Component) templ.Component,
	content templ.Component,
) error

Page renders content for a full navigation or an HTMX request: HTMX requests receive the bare content fragment, while normal navigations receive content wrapped by layout. The Vary: HX-Request header keeps the two variants cached separately. layout takes the content component and returns the full-page component (e.g. the caller's own app shell).

func Render

func Render(ctx context.Context, w http.ResponseWriter, status int, c templ.Component) error

Render writes c as an HTML response with the given status code. The component is rendered into a buffer first: if rendering fails, nothing is written to w (the status is not committed), so the caller can send an error response instead. On success the status, headers, and body are written together. Pages are small, so buffering is preferable to streaming a half-written response; genuinely streamed responses (e.g. SSE) should not use this seam.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL