I know that in go
templates I can call function named add
for expression like 1 + 1
. But how named function for expression like 2 - 1
?
gomplate is a template renderer which supports a growing list of datasources, such as: JSON (including EJSON - encrypted JSON), YAML, AWS EC2 metadata, and secrets. Come chat with developers and community in the on and on !
Overview. Package template implements data-driven templates for generating textual output. To generate HTML output, see package html/template, which has the same interface as this package but automatically secures HTML output against certain attacks. Templates are executed by applying them to a data structure.
Go templates are a powerful method to customize output however you want, whether you're creating a web page, sending an e-mail, working with Buffalo, Go-Hugo, or just using some CLI such as kubectl. There're two packages operating with templates — text/template and html/template .
There is no add
function included by default. You can however, easily write such functions yourself. For example:
tmpl := template.Must(template.New("").Funcs(template.FuncMap{
"minus": func(a, b int) int {
return a - b
},
}).Parse("{{ minus 5 2 }}"))
tmpl.Execute(os.Stdout, nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With