Standard library / text/template/parse

text/template/parse.IsEmptyTree()

Reports whether a node contains only whitespace or comments. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func IsEmptyTree(n Node) bool

Parameters & Attributes

NameTypeDescription
nNodeInput to the operation as described above.

Return Value

bool

Reports whether a node contains only whitespace or comments.

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() {  fmt.Println(parse.IsEmptyTree(tree(" {{/* note */}} ").Root) && !parse.IsEmptyTree(tree("Hi").Root))}
Go Reference