Commit 7a42e60b authored by Matthew Holt's avatar Matthew Holt

templates: Support for nested include files

i.e. included files are also parsed as templates
parent a790db13
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment