Standard library / text/template/parse

text/template/parse.ChainNode.Add()

Add appends a field name with a leading period; an absent period or empty name panics. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (c *ChainNode) Add(field string)

Parameters & Attributes

NameTypeDescription
fieldstringInput to the operation as described above.

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("{{(.User).Name}}")  n := t.Root.Nodes[0].(*parse.ActionNode).Pipe.Cmds[0].Args[0].(*parse.ChainNode)  n.Add(".Length")  fmt.Println(n.Field[1] == "Length")}
Go Reference