From ade84c9358ec7749cbc57c0d6a83fe5dd6e52f8f Mon Sep 17 00:00:00 2001 From: Edd Salkield Date: Sun, 25 Sep 2022 18:03:39 +0100 Subject: [PATCH] templates.go: Support default base templates If a base template is not found in the current directory, look for a default base template at templates/_default/base.ext. Also prevent partial templates from inheriting from base templates. --- templates.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/templates.go b/templates.go index ff00ee7..6070b78 100644 --- a/templates.go +++ b/templates.go @@ -148,11 +148,19 @@ func (t *Templates) Load(dir string, exts []string) error { if _, ok := extsMap[ext]; !ok { continue } + if strings.HasPrefix(path, "_partials/") { + continue + } basePath := pathpkg.Join(pathpkg.Dir(path), "base"+ext) if path == basePath { continue } - if base, ok := t.tmpls[basePath]; ok { + base, ok := t.tmpls[basePath] + if !ok { + basePath = pathpkg.Join("_default", "base"+ext) + base, ok = t.tmpls[basePath] + } + if ok { tmpl, err := base.Clone() if err != nil { return err