Skip to content
Go to file
Cannot retrieve contributors at this time
57 lines (45 sloc) 1.36 KB
package statictemplate
import (
htmlTemplate "html/template"
textTemplate "text/template"
_ "unsafe"
type wrappedTemplate interface {
Tree() *parse.Tree
Lookup(name string) (wrappedTemplate, error)
Name() string
type textTemplateWrapper struct {
var _ wrappedTemplate = textTemplateWrapper{}
func (t textTemplateWrapper) Tree() *parse.Tree {
return t.Template.Tree
func (t textTemplateWrapper) Lookup(name string) (wrappedTemplate, error) {
return textTemplateWrapper{t.Template.Lookup(name)}, nil
type htmlTemplateWrapper struct {
var _ wrappedTemplate = htmlTemplateWrapper{}
func (t htmlTemplateWrapper) Tree() *parse.Tree {
return t.Template.Tree
func (t htmlTemplateWrapper) Lookup(name string) (wrappedTemplate, error) {
temp, err := lookupAndEscapeTemplate(t.Template, name)
return htmlTemplateWrapper{temp}, err
func wrap(template interface{}) wrappedTemplate {
switch template := template.(type) {
case *htmlTemplate.Template:
return htmlTemplateWrapper{template}
case *textTemplate.Template:
return textTemplateWrapper{template}
panic("invalid template passed in")
//go:linkname lookupAndEscapeTemplate html/template.(*Template).lookupAndEscapeTemplate
func lookupAndEscapeTemplate(t *htmlTemplate.Template, name string) (*htmlTemplate.Template, error)
You can’t perform that action at this time.