ref: beff6805340203434d2b8ca738194b781fd37b83
parent: be46a4b9b03df85f786866da7a3a657f978a26bd
author: bep <[email protected]>
date: Sat Apr 18 09:58:35 EDT 2015
Expand the ACE base template lookup pattern The previous implementation didn't easily support the use case "I want one base template for the single pages, another for the rest". The new lookup order is: 1. <current-path>/<template-name>-baseof.ace, e.g. list-baseof.ace 2. <current-path>/baseof.ace 3. _default/<template-name>-baseof.ace, e.g. list-baseof.ace. 4. _default/baseof.ace
--- a/tpl/template.go
+++ b/tpl/template.go
@@ -15,6 +15,7 @@
import (
"bytes"
+ "fmt"
"github.com/eknkc/amber"
bp "github.com/spf13/hugo/bufferpool"
"github.com/spf13/hugo/helpers"
@@ -279,14 +280,26 @@
return err
}
if needsBase {
- // Look for the base first in the current path, then in _default.
- p := filepath.Join(filepath.Dir(path), baseAceFilename)
- if ok, err := helpers.Exists(p, hugofs.OsFs); err == nil && ok {
- baseTemplatePath = p
- } else {
- p := filepath.Join(absPath, "_default", baseAceFilename)
- if ok, err := helpers.Exists(p, hugofs.OsFs); err == nil && ok {
- baseTemplatePath = p
+
+ // Look for base template in the follwing order:
+ // 1. <current-path>/<template-name>-baseof.ace, e.g. list-baseof.ace.
+ // 2. <current-path>/baseof.ace
+ // 3. _default/<template-name>-baseof.ace, e.g. list-baseof.ace.
+ // 4. _default/baseof.ace
+
+ currBaseAceFilename := fmt.Sprintf("%s-%s", helpers.Filename(path), baseAceFilename)
+ templateDir := filepath.Dir(path)
+
+ pathsToCheck := []string{
+ filepath.Join(templateDir, currBaseAceFilename),
+ filepath.Join(templateDir, baseAceFilename),
+ filepath.Join(absPath, "_default", currBaseAceFilename),
+ filepath.Join(absPath, "_default", baseAceFilename)}
+
+ for _, pathToCheck := range pathsToCheck {
+ if ok, err := helpers.Exists(pathToCheck, hugofs.OsFs); err == nil && ok {
+ baseTemplatePath = pathToCheck
+ break
}
}
}