summaryrefslogtreecommitdiffstats
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-04-04 17:21:04 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-04-04 17:21:04 +0200
commitbc36d468ab56b5bcf01c3dc1478b1818dd17e4ff (patch)
tree6fe31e902d30fa4ad12783db593d4f83a1f0d5a7 /tpl
parent7da1b65968cd78970de8c8b61f5056dc7b0ec6b2 (diff)
tplimpl: Reintroduce the double template lookup in Partial
So it works as before without the html suffix. Fixes #3272
Diffstat (limited to 'tpl')
-rw-r--r--tpl/tplimpl/templateFuncster.go4
-rw-r--r--tpl/tplimpl/template_funcs_test.go34
2 files changed, 38 insertions, 0 deletions
diff --git a/tpl/tplimpl/templateFuncster.go b/tpl/tplimpl/templateFuncster.go
index 1fbaebd43..ddcafedfd 100644
--- a/tpl/tplimpl/templateFuncster.go
+++ b/tpl/tplimpl/templateFuncster.go
@@ -63,6 +63,10 @@ func (t *templateFuncster) partial(name string, contextList ...interface{}) (int
for _, n := range []string{"partials/" + name, "theme/partials/" + name} {
templ := t.Tmpl.Lookup(n)
+ if templ == nil {
+ // For legacy reasons.
+ templ = t.Tmpl.Lookup(n + ".html")
+ }
if templ != nil {
b := bp.GetBuffer()
defer bp.PutBuffer(b)
diff --git a/tpl/tplimpl/template_funcs_test.go b/tpl/tplimpl/template_funcs_test.go
index b50765fcb..075581c66 100644
--- a/tpl/tplimpl/template_funcs_test.go
+++ b/tpl/tplimpl/template_funcs_test.go
@@ -2908,6 +2908,40 @@ func TestPartialHTMLAndText(t *testing.T) {
}
+func TestPartialHTMLWithNoSuffix(t *testing.T) {
+ t.Parallel()
+ config := newDepsConfig(viper.New())
+
+ data := struct {
+ Name string
+ }{
+ Name: "a",
+ }
+
+ config.WithTemplate = func(templ tpl.TemplateHandler) error {
+ if err := templ.AddTemplate("htmlTemplate.html", `HTML Test Partial: {{ partial "test" . -}}`); err != nil {
+ return err
+ }
+
+ if err := templ.AddTemplate("partials/test.html", "HTML Name: {{ .Name }}"); err != nil {
+ return err
+ }
+ return nil
+ }
+
+ de, err := deps.New(config)
+ require.NoError(t, err)
+ require.NoError(t, de.LoadResources())
+
+ templ := de.Tmpl.Lookup("htmlTemplate.html")
+ require.NotNil(t, templ)
+ resultHTML, err := templ.ExecuteToString(data)
+ require.NoError(t, err)
+
+ require.Contains(t, resultHTML, "HTML Test Partial: HTML Name: a")
+
+}
+
func TestPartialWithError(t *testing.T) {
t.Parallel()
config := newDepsConfig(viper.New())