Standard library / text/template/parse
text/template/parse.Parse()
Parses trusted source into a map of named trees; supply known function names in function maps. No rendering occurs. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]any) (map[string]*Tree, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Name of the template. |
| text | string | Template source text, authored by a trusted developer. |
| leftDelim | string | Input to the operation as described above. |
| rightDelim | string | Input to the operation as described above. |
| funcs | ...map[string]any | Input to the operation as described above. |
Return Value
(map[string]*Tree, error)
Parses trusted source into a map of named trees; supply known function names in function maps.
Working Example
Example Snippetgo
package main
import ( "fmt" "text/template/parse")
func check(e error) { if e != nil { panic(e) }}
func main() { ts, e := parse.Parse("demo", `{{define "header"}}Hi{{end}}{{template "header"}}`, "", "") check(e) fmt.Println(len(ts) == 2 && ts["header"].Root.String() == "Hi")}