Standard library / text/template/parse

text/template/parse.IdentifierNode.SetTree()

SetTree associates the identifier with its parent tree and returns the same identifier. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (i *IdentifierNode) SetTree(t *Tree) *IdentifierNode

Parameters & Attributes

NameTypeDescription
t*TreeTemplate returned by a constructor or parse call.

Return Value

*IdentifierNode

SetTree associates the identifier with its parent tree and returns the same identifier.

Working Example

Example Snippetgo
package main
import (  "fmt"  "text/template/parse")
func tree(s string) *parse.Tree {  t := parse.New("demo")  t.Mode = parse.ParseComments | parse.SkipFuncCheck  _, e := t.Parse(s, "", "", map[string]*parse.Tree{})  if e != nil {    panic(e)  }  return t}func action(s string) *parse.ActionNode { return tree(s).Root.Nodes[0].(*parse.ActionNode) }
func main() {  t := tree("{{printf \"x\"}}")  n := t.Root.Nodes[0].(*parse.ActionNode).Pipe.Cmds[0].Args[0].(*parse.IdentifierNode)  fmt.Println(n.SetTree(t) == n)}
Go Reference