functions

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

All returns all the templating functions

Example
htmlTemplate := `
<html>
	<head>
		<title>{{ .title }}</title>
	<head>
	<body>
		<ul>
		{{- range .items }}
			{{- include "listItem" . | tabIndent 3 -}}
		{{- end }}
		</ul>
	</body>
</html>

{{- define "listItem" }}
<li>
	{{.}}
</li>
{{- end -}}`

data := map[string]any{
	"title": "My List Of Doom",
	"items": []string{
		"Acquire lair",
		"Acquire henchmen",
		"Acquire doomsday weapon",
	},
}

t := template.New("example")
t.Funcs(All(t))
t, _ = t.Parse(htmlTemplate)
_ = t.ExecuteTemplate(os.Stdout, "example", data)
Output:

<html>
	<head>
		<title>My List Of Doom</title>
	<head>
	<body>
		<ul>
			<li>
				Acquire lair
			</li>
			<li>
				Acquire henchmen
			</li>
			<li>
				Acquire doomsday weapon
			</li>
		</ul>
	</body>
</html>

func CombineFunctionLists added in v0.9.5

func CombineFunctionLists(fnList ...template.FuncMap) template.FuncMap

CombineFunctionLists together from zero more supplied lists

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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