本文整理汇总了Golang中html/template.Template.Templates方法的典型用法代码示例。如果您正苦于以下问题:Golang Template.Templates方法的具体用法?Golang Template.Templates怎么用?Golang Template.Templates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类html/template.Template
的用法示例。
在下文中一共展示了Template.Templates方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ParseGlob
// Pase files match the [pattern] and store file path of each template name in templateMapPaths
func ParseGlob(templates *template.Template, pattern string) (*template.Template, error) {
filePaths, err := filepath.Glob(pattern)
if err != nil {
return templates, err
}
if len(filePaths) == 0 {
return templates, fmt.Errorf("mangotemplate.ParseGlob: pattern matches no files: %#q", pattern)
}
for _, path := range filePaths {
_, err := templates.ParseFiles(path)
if err != nil {
return templates, err
}
for _, parsedTemplate := range templates.Templates() {
if _, ok := templateMapPaths[parsedTemplate.Name()]; ok {
continue
}
templateMapPaths[parsedTemplate.Name()] = path
}
}
return templates, nil
}
示例2: parseTemplates
func parseTemplates(tpl *template.Template) (err error) {
templatesToBeParsed := []string{tpl.Name()}
for len(templatesToBeParsed) != 0 {
name := templatesToBeParsed[0]
templatesToBeParsed = templatesToBeParsed[1:]
parsed := false
for _, t := range tpl.Templates() {
if tpl.Name() != name && t.Name() == name {
parsed = true
break
}
}
if !parsed {
content, err := readTemplate(name)
if err != nil {
return err
}
_, err = tpl.Parse(content)
check(err)
for _, matched := range templateKeyword.FindAllStringSubmatch(content, -1) {
templatesToBeParsed = append(templatesToBeParsed, matched[1])
}
}
}
return
}
示例3: getTemplate
func getTemplate(tpl *template.Template) (s string) {
for _, j := range tpl.Templates() {
s += j.Name() + ", "
}
return s
}
示例4: debugPrintLoadTemplate
func debugPrintLoadTemplate(tmpl *template.Template) {
if IsDebugging() {
var buf bytes.Buffer
for _, tmpl := range tmpl.Templates() {
buf.WriteString("\t- ")
buf.WriteString(tmpl.Name())
buf.WriteString("\n")
}
debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())
}
}
示例5: printTemplate
func printTemplate(tpl *template.Template, max, level int) {
if level > max {
return
}
log.Printf("Printing template: %v @ %v", tpl.Name(), level)
for i, j := range tpl.Templates() {
log.Printf("TEMPLATE: %v=%v", i, j.Name())
}
for _, j := range tpl.Templates() {
printTemplate(j, max, level+1)
}
}
示例6: parseTemplates
func parseTemplates(tpl *template.Template) (err error) {
templatesToBeParsed := []string{tpl.Name()}
for len(templatesToBeParsed) != 0 {
name := templatesToBeParsed[0]
templatesToBeParsed = templatesToBeParsed[1:]
parsed := false
for _, t := range tpl.Templates() {
if tpl.Name() != name && t.Name() == name {
parsed = true
break
}
}
if !parsed {
content, path, err := readTemplate(name)
if err != nil {
return err
}
if _, err = tpl.New(path).Parse(content); err != nil {
if strings.Contains(err.Error(), "redefinition of template") {
return fmt.Errorf("A redefinition error raised while parsing [%s]. Did you happen to put the HTML comments outside the {{define}} block?)", name)
}
return err
}
for _, matched := range templateKeyword.FindAllStringSubmatch(content, -1) {
templatesToBeParsed = append(templatesToBeParsed, matched[1])
}
}
}
return
}