tpl

package
v0.0.0-...-2f19caa Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Funcs = template.FuncMap{
	"json": func(v any) template.JS {
		a, err := json.Marshal(v)
		if err != nil {
			slog.Error("Error marshalling JSON: " + err.Error())
			return "{}"
		}
		return template.JS(a)
	},
	"jsonPretty": func(v any) template.JS {
		a, err := json.MarshalIndent(v, "", "\t")
		if err != nil {
			slog.Error("Error marshalling JSON: " + err.Error())
			return "{}"
		}
		return template.JS(a)
	},
	"safeHTML": func(v any) template.HTML {
		return template.HTML(fmt.Sprint(v))
	},
	"safeAttr": func(v any) template.HTMLAttr {
		return template.HTMLAttr(fmt.Sprint(v))
	},
	"renderComponent": func(renderer componentRenderer) string {
		buf := bytes.Buffer{}
		err := renderer.Render(context.Background(), &buf)
		if err != nil {
			slog.Error("Rendering component: " + err.Error())
			return ""
		}
		return buf.String()
	},
}

Funcs is a map of utility functions that can be used in the std html/template package.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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