render

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// The function map to use when rendering templates.
	FuncMap = DefaultFuncMap()
)

Functions

func DefaultFuncMap

func DefaultFuncMap() template.FuncMap

DefaultFuncMap returns a map of functions for the template engine. It includes everything from sprig.FuncMap, plus a number of functions from flect.

func File

func File(path string, data any) (string, error)

File renders the file at path with data.

func String

func String(s string, data any) (string, error)

String renders the template string with data.

Types

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template is a lightweight wrapper for template strings.

Since it implements the encoding.TextMarshaler and encoding.TextUnmarshaler interfaces, it can be used with JSON or YAML fields containing template strings.

func Compile

func Compile(s string) (*Template, error)

Compile parses a template string and returns, if successful, a new Template that can be rendered.

func MustCompile

func MustCompile(s string) *Template

MustCompile behaves like Compile, but panics on error.

func (*Template) MarshalText

func (ts *Template) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Template) Render

func (ts *Template) Render(data any) (string, error)

Render renders the template using data.

func (*Template) UnmarshalText

func (ts *Template) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

Jump to

Keyboard shortcuts

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