mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
tplimpl: Reintroduce the double template lookup in Partial
So it works as before without the html suffix. Fixes #3272
This commit is contained in:
parent
7da1b65968
commit
bc36d468ab
2 changed files with 38 additions and 0 deletions
|
@ -63,6 +63,10 @@ func (t *templateFuncster) partial(name string, contextList ...interface{}) (int
|
||||||
|
|
||||||
for _, n := range []string{"partials/" + name, "theme/partials/" + name} {
|
for _, n := range []string{"partials/" + name, "theme/partials/" + name} {
|
||||||
templ := t.Tmpl.Lookup(n)
|
templ := t.Tmpl.Lookup(n)
|
||||||
|
if templ == nil {
|
||||||
|
// For legacy reasons.
|
||||||
|
templ = t.Tmpl.Lookup(n + ".html")
|
||||||
|
}
|
||||||
if templ != nil {
|
if templ != nil {
|
||||||
b := bp.GetBuffer()
|
b := bp.GetBuffer()
|
||||||
defer bp.PutBuffer(b)
|
defer bp.PutBuffer(b)
|
||||||
|
|
|
@ -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) {
|
func TestPartialWithError(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
config := newDepsConfig(viper.New())
|
config := newDepsConfig(viper.New())
|
||||||
|
|
Loading…
Reference in a new issue