summaryrefslogtreecommitdiffstats
path: root/tpl/tplimpl/template.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-11-26 09:44:31 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-11-26 12:55:00 +0100
commit96f09659ce8752c32a2a6429c9faf23be4faa091 (patch)
treeba179894eddd24214697b98a19926c4f3c9a9b09 /tpl/tplimpl/template.go
parent03b369e6726ed8a732c07db48f7209425c434bbe (diff)
Fix language handling in ExecuteAsTemplate
Fixes #6331
Diffstat (limited to 'tpl/tplimpl/template.go')
-rw-r--r--tpl/tplimpl/template.go27
1 files changed, 10 insertions, 17 deletions
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go
index 35407722a..602777524 100644
--- a/tpl/tplimpl/template.go
+++ b/tpl/tplimpl/template.go
@@ -98,8 +98,6 @@ type templateHandler struct {
text *textTemplates
html *htmlTemplates
- extTextTemplates []*textTemplate
-
amberFuncMap template.FuncMap
errors []*templateErr
@@ -153,15 +151,7 @@ func (t *templateHandler) addShortcodeVariant(name string, info tpl.Info, templ
}
}
-// NewTextTemplate provides a text template parser that has all the Hugo
-// template funcs etc. built-in.
-func (t *templateHandler) NewTextTemplate() tpl.TemplateParseFinder {
- t.mu.Lock()
- defer t.mu.Unlock()
-
- tt := &textTemplate{t: texttemplate.New("")}
- t.extTextTemplates = append(t.extTextTemplates, tt)
-
+func (t *templateHandler) wrapTextTemplate(tt *textTemplate) tpl.TemplateParseFinder {
return struct {
tpl.TemplateParser
tpl.TemplateLookup
@@ -283,8 +273,11 @@ func (t *templateHandler) clone(d *deps.Deps) *templateHandler {
shortcodes: make(map[string]*shortcodeTemplates),
templateInfo: t.templateInfo,
html: &htmlTemplates{t: template.Must(t.html.t.Clone()), overlays: make(map[string]*template.Template), templatesCommon: t.html.templatesCommon},
- text: &textTemplates{textTemplate: &textTemplate{t: texttemplate.Must(t.text.t.Clone())}, overlays: make(map[string]*texttemplate.Template), templatesCommon: t.text.templatesCommon},
- errors: make([]*templateErr, 0),
+ text: &textTemplates{
+ textTemplate: &textTemplate{t: texttemplate.Must(t.text.t.Clone())},
+ standalone: &textTemplate{t: texttemplate.New("")},
+ overlays: make(map[string]*texttemplate.Template), templatesCommon: t.text.templatesCommon},
+ errors: make([]*templateErr, 0),
}
for k, v := range t.shortcodes {
@@ -302,6 +295,7 @@ func (t *templateHandler) clone(d *deps.Deps) *templateHandler {
}
d.Tmpl = c
+ d.TextTmpl = c.wrapTextTemplate(c.text.standalone)
c.initFuncs()
@@ -339,6 +333,7 @@ func newTemplateAdapter(deps *deps.Deps) *templateHandler {
}
textT := &textTemplates{
textTemplate: &textTemplate{t: texttemplate.New("")},
+ standalone: &textTemplate{t: texttemplate.New("")},
overlays: make(map[string]*texttemplate.Template),
templatesCommon: common,
}
@@ -431,6 +426,7 @@ func (t *textTemplates) setTemplateFuncster(f *templateFuncster) {
type textTemplates struct {
*templatesCommon
*textTemplate
+ standalone *textTemplate
clone *texttemplate.Template
cloneClone *texttemplate.Template
@@ -468,6 +464,7 @@ func (t *textTemplates) lookup(name string) *texttemplate.Template {
func (t *templateHandler) setFuncs(funcMap map[string]interface{}) {
t.html.setFuncs(funcMap)
t.text.setFuncs(funcMap)
+ t.setFuncMapInTemplate(t.text.standalone.t, funcMap)
}
// SetFuncs replaces the funcs in the func maps with new definitions.
@@ -781,10 +778,6 @@ func (t *templateHandler) initFuncs() {
}
}
- for _, extText := range t.extTextTemplates {
- extText.t.Funcs(funcMap)
- }
-
// Amber is HTML only.
t.amberFuncMap = template.FuncMap{}