mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
tplimpl: Allow text partials in HTML templates
Most obvius benefit of this is to include CSS partials with css file suffix into HTML templates. A valid workaround would be to rename the file `mystyles.html`, but that doesn't work too good for external editors etc. The css partial is a method used in some themes before Hugo 0.20, but then it stopped working. This commit reintroduces that behaviour. Note that the regular layout lookups for text templates, i.e. "single.json" will be prefixed with "_text/" on lookup and will only match in the text collection. Fixes #3273
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"strings"
|
||||
texttemplate "text/template"
|
||||
|
||||
bp "github.com/spf13/hugo/bufferpool"
|
||||
|
||||
@@ -31,17 +32,12 @@ type templateFuncster struct {
|
||||
cachedPartials partialCache
|
||||
image *imageHandler
|
||||
|
||||
// Make sure each funcster gets its own TemplateFinder to get
|
||||
// proper text and HTML template separation.
|
||||
Tmpl templateFuncsterTemplater
|
||||
|
||||
*deps.Deps
|
||||
}
|
||||
|
||||
func newTemplateFuncster(deps *deps.Deps, t templateFuncsterTemplater) *templateFuncster {
|
||||
func newTemplateFuncster(deps *deps.Deps) *templateFuncster {
|
||||
return &templateFuncster{
|
||||
Deps: deps,
|
||||
Tmpl: t,
|
||||
cachedPartials: partialCache{p: make(map[string]interface{})},
|
||||
image: &imageHandler{fs: deps.Fs, imageConfigCache: map[string]image.Config{}},
|
||||
}
|
||||
@@ -75,14 +71,12 @@ func (t *templateFuncster) partial(name string, contextList ...interface{}) (int
|
||||
return "", err
|
||||
}
|
||||
|
||||
switch t.Tmpl.(type) {
|
||||
case *htmlTemplates:
|
||||
return template.HTML(b.String()), nil
|
||||
case *textTemplates:
|
||||
if _, ok := templ.Template.(*texttemplate.Template); ok {
|
||||
return b.String(), nil
|
||||
default:
|
||||
panic("Unknown type")
|
||||
}
|
||||
|
||||
return template.HTML(b.String()), nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user