Golang html/template.Template.Templates function example

package html/template

Templates returns a slice of the templates associated with t, including t itself.

Golang html/template.Template.Templates function usage example

 package main

 import (
 "fmt"
 "html/template"
 )

 func main() {

 t := template.New("HELLO")

 t1 := template.Must(t.ParseGlob("*.html"))

 templates := t1.Templates() // < -- here

 fmt.Println("Total templates detected from ParseGlob : ", len(templates))

 }

Sample output : (depending on how many *.html files in the detected)

Total templates detected from ParseGlob : 3

2 html files will be counted as 3 because Templates() include it self.

Reference :

http://golang.org/pkg/html/template/#Template.Templates

Advertisement