From 7a42e60bcb9995592248e7f249066e80114a5c72 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 30 Jun 2015 18:20:36 -0600 Subject: [PATCH 1/2] templates: Support for nested include files i.e. included files are also parsed as templates --- middleware/templates/context.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/middleware/templates/context.go b/middleware/templates/context.go index bdecea8b..6f23e7f3 100644 --- a/middleware/templates/context.go +++ b/middleware/templates/context.go @@ -1,10 +1,12 @@ package templates import ( + "bytes" "io/ioutil" "net" "net/http" "net/url" + "text/template" "time" "github.com/mholt/caddy/middleware" @@ -26,8 +28,24 @@ func (c context) Include(filename string) (string, error) { if err != nil { return "", err } + body, err := ioutil.ReadAll(file) - return string(body), err + if err != nil { + return "", err + } + + tpl, err := template.New(filename).Parse(string(body)) + if err != nil { + return "", err + } + + var buf bytes.Buffer + err = tpl.Execute(&buf, c) + if err != nil { + return "", err + } + + return buf.String(), nil } // Date returns the current timestamp in the specified format From 16f18bfeffc6f1c028b93a49153224026e153491 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 30 Jun 2015 18:21:12 -0600 Subject: [PATCH 2/2] Update change list --- dist/CHANGES.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/CHANGES.txt b/dist/CHANGES.txt index 76027f8d..b76e2ee3 100644 --- a/dist/CHANGES.txt +++ b/dist/CHANGES.txt @@ -2,16 +2,18 @@ CHANGES +- Removed git directive from core; now available as an addon - browse: Sort by clicking column heading or using query string - core: Serving hostname that doesn't resolve issues warning then listens on 0.0.0.0 - errors: Missing error page during parse time is warning, not error - fastcgi: Fix for backend responding without status text -- git: Pull changes immediately with GitHub webhook +- fastcgi: Fix PATH_TRANSLATED when PATH_INFO is empty (RFC 3875) - gzip: Enable by file path and/or extension - gzip: Customize compression level - log: Fix for missing status in log entry when error unhandled - proxy: Strip prefix from path for proxy to path - redir: Meta tag redirects +- templates: Support for nested includes 0.7.1 (June 2, 2015)