mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-08 23:40:40 +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:
@@ -97,23 +97,21 @@ func (t *templateHandler) PrintErrors() {
|
||||
// Lookup tries to find a template with the given name in both template
|
||||
// collections: First HTML, then the plain text template collection.
|
||||
func (t *templateHandler) Lookup(name string) *tpl.TemplateAdapter {
|
||||
var te *tpl.TemplateAdapter
|
||||
|
||||
isTextTemplate := strings.HasPrefix(name, textTmplNamePrefix)
|
||||
|
||||
if isTextTemplate {
|
||||
if strings.HasPrefix(name, textTmplNamePrefix) {
|
||||
// The caller has explicitly asked for a text template, so only look
|
||||
// in the text template collection.
|
||||
// The templates are stored without the prefix identificator.
|
||||
name = strings.TrimPrefix(name, textTmplNamePrefix)
|
||||
te = t.text.Lookup(name)
|
||||
} else {
|
||||
te = t.html.Lookup(name)
|
||||
return t.text.Lookup(name)
|
||||
}
|
||||
|
||||
if te == nil {
|
||||
return nil
|
||||
// Look in both
|
||||
if te := t.html.Lookup(name); te != nil {
|
||||
return te
|
||||
}
|
||||
|
||||
return te
|
||||
return t.text.Lookup(name)
|
||||
}
|
||||
|
||||
func (t *templateHandler) clone(d *deps.Deps) *templateHandler {
|
||||
@@ -459,9 +457,10 @@ func (t *templateHandler) loadTemplates(absPath string, prefix string) {
|
||||
|
||||
func (t *templateHandler) initFuncs() {
|
||||
|
||||
// The template funcs need separation between text and html templates.
|
||||
// Both template types will get their own funcster instance, which
|
||||
// in the current case contains the same set of funcs.
|
||||
for _, funcsterHolder := range []templateFuncsterTemplater{t.html, t.text} {
|
||||
funcster := newTemplateFuncster(t.Deps, funcsterHolder)
|
||||
funcster := newTemplateFuncster(t.Deps)
|
||||
|
||||
// The URL funcs in the funcMap is somewhat language dependent,
|
||||
// so we need to wait until the language and site config is loaded.
|
||||
|
Reference in New Issue
Block a user