functions

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package functions collects all the functions defined for the various template methods together into a single package

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
Package console provides methods for unix terminal operations
Package console provides methods for unix terminal operations
Package datetime provides methods for manipulating dates and times in templates
Package datetime provides methods for manipulating dates and times in templates
Package encoding provides template methods related to various data encodings
Package encoding provides template methods related to various data encodings
Package helper provides common methods used by the various template functions
Package helper provides common methods used by the various template functions
Package list provides methods for manipulating lists in templates
Package list provides methods for manipulating lists in templates
Package logic provides conditional operations for templates
Package logic provides conditional operations for templates
Package math provides mathematical operations in templates
Package math provides mathematical operations in templates
Package strings provides methods for manipulating strings in templates
Package strings provides methods for manipulating strings in templates
Package templates provides methods for operating on templates
Package templates provides methods for operating on templates

Jump to

Keyboard shortcuts

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