Standard library / text/template/parse

text/template/parse.PipeNode

Pipeline with commands and optional variable declarations. Inspect the exported fields of a parsed node. This low-level package is intended for tooling, not ordinary rendering. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
type PipeNode struct {  NodeType  Pos
  Line     int  IsAssign bool  Decl     []*VariableNode  Cmds     []*CommandNode}

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 \"%s\"}}")  n := t.Root.Nodes[0].(*parse.ActionNode).Pipe  fmt.Println(len(n.Cmds) == 2)}
Go Reference