Documentation
¶
Overview ¶
Package tplutil provides more convient way to use text/template inside the code.
Consider (using text/template):
var myTpl = template.Must(template.New("name").Parse(
"Some list:\n" +
"{{range .}}" +
"# {{.}}\n" +
"{{end}}"))
`gofmt` will ruin any attempt to format code above.
And with tplutil:
var myTpl = template.Must(template.New("name").Parse(tplutil.Strip(`
Some list:{{"\n"}}
{{range .}}
# {{.}}{{"\n"}}
{{end}}
`)))
Output will be exactly the same.
Any indenting whitespaces and newlines will be ignored. If must, they should be specified by using syntax
`{{" "}}` or `{{"\n"}}`.
It also provide `{{last}}` function to check on last element of pipeline:
var myTpl = template.Must(template.New("asd").Funcs(tplutil.Last).Parse(
tplutil.Strip(`
Some list:{{"\n"}}
{{range $i, $_ := .}}
{{.}}
{{if not (last $i $)}}
{{"\n"}}{{/* do not append newline to the last element */}}
{{end}}
{{end}}
`))
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ExecuteToString ¶
ExecuteToString applies a parsed template to specified data object and returns it output as return value. It can return partial result if execution can'tpl be proceed because of error.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.