summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/templates/templates.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/templates/templates.go')
-rw-r--r--modules/caddyhttp/templates/templates.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/modules/caddyhttp/templates/templates.go b/modules/caddyhttp/templates/templates.go
index 9a41b6d..1cd347c 100644
--- a/modules/caddyhttp/templates/templates.go
+++ b/modules/caddyhttp/templates/templates.go
@@ -27,10 +27,7 @@ import (
)
func init() {
- caddy.RegisterModule(caddy.Module{
- Name: "http.handlers.templates",
- New: func() interface{} { return new(Templates) },
- })
+ caddy.RegisterModule(Templates{})
}
// Templates is a middleware which execute response bodies as templates.
@@ -40,6 +37,14 @@ type Templates struct {
Delimiters []string `json:"delimiters,omitempty"`
}
+// CaddyModule returns the Caddy module information.
+func (Templates) CaddyModule() caddy.ModuleInfo {
+ return caddy.ModuleInfo{
+ Name: "http.handlers.templates",
+ New: func() caddy.Module { return new(Templates) },
+ }
+}
+
// Provision provisions t.
func (t *Templates) Provision(ctx caddy.Context) error {
if t.MIMETypes == nil {
@@ -108,7 +113,8 @@ func (t *Templates) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
func (t *Templates) executeTemplate(rr caddyhttp.ResponseRecorder, r *http.Request) error {
var fs http.FileSystem
if t.IncludeRoot != "" {
- fs = http.Dir(t.IncludeRoot)
+ repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer)
+ fs = http.Dir(repl.ReplaceAll(t.IncludeRoot, "."))
}
ctx := &templateContext{