render

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package render writes template values into a page, each with the escaper of the HTML context it lands in. Generated code calls it; apps do not.

Index

Constants

View Source
const UnsafeURL = "about:invalid#aicoded-unsafe-url"

UnsafeURL replaces a URL value whose scheme is not http, https or mailto.

Variables

This section is empty.

Functions

func Attr

func Attr(w io.Writer, v any) error

Attr writes v inside a double-quoted attribute value.

func Format

func Format(v any) string

Format returns v as display text.

func HTML

func HTML(w io.Writer, v web.SafeHTML) error

HTML writes markup that is already safe.

func If

func If[T any](cond bool, whenTrue, whenFalse T) T

If returns whenTrue if cond holds and whenFalse otherwise. Templates write it as cond ? a : b.

func JSON

func JSON(w io.Writer, v any) error

JSON writes v as the body of a <script type="application/json"> element.

func Text

func Text(w io.Writer, v any) error

Text writes v as element text, including the text of <title> and <textarea>.

func URL

func URL(w io.Writer, v any) error

URL writes v as a whole URL attribute value, as in href="{{ link }}". A value whose scheme is not http, https or mailto becomes UnsafeURL.

func URLPart

func URLPart(w io.Writer, v any) error

URLPart writes v in a URL attribute value after a fixed path or scheme and before any ? or #, as in href="/notes/{{ id }}".

func URLPathStart

func URLPathStart(w io.Writer, v any) error

URLPathStart writes v in a URL attribute value right after its leading "/", as in href="/{{ slug }}". It encodes a leading "/" of v and writes an empty v as ".", so the URL never starts with "//" or "/\", which browsers read as the address of another site.

func URLQuery

func URLQuery(w io.Writer, v any) error

URLQuery writes v in a URL attribute value after ? or #, as in href="/find?q={{ q }}".

Types

This section is empty.

Jump to

Keyboard shortcuts

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