renderer

package
v0.0.0-...-9401fe5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTMLTemplRenderer

type HTMLTemplRenderer struct {
	FallbackHtmlRenderer render.HTMLRender
}

HTMLTemplRenderer is a custom renderer that can handle templ.Component.

func (*HTMLTemplRenderer) Instance

func (r *HTMLTemplRenderer) Instance(s string, d interface{}) render.Render

Instance implements gin's HTMLRender interface. If the data is a templ.Component, it returns our custom Renderer struct; otherwise, it falls back to the default provided gin HTML renderer (if set).

NOTE: This method uses context.Background() because the HTMLRender interface has no access to the HTTP request context. Handlers should always use renderer.New(ctx, status, component) instead of c.HTML() to ensure proper context propagation (cancellation, timeouts, request-scoped values).

type Renderer

type Renderer struct {
	Ctx       context.Context
	Status    int
	Component templ.Component
}

Renderer implements gin.Render for templ components.

func New

func New(ctx context.Context, status int, component templ.Component) *Renderer

New creates a new Renderer with a given context, status code, and templ component.

func (Renderer) Render

func (t Renderer) Render(w http.ResponseWriter) error

Render writes headers and renders the templ component to the HTTP response.

func (Renderer) WriteContentType

func (t Renderer) WriteContentType(w http.ResponseWriter)

WriteContentType sets "Content-Type: text/html; charset=utf-8".

Jump to

Keyboard shortcuts

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