mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-03 06:37:14 +01:00
templates: Support for nested include files
i.e. included files are also parsed as templates
This commit is contained in:
parent
a790db134d
commit
7a42e60bcb
1 changed files with 19 additions and 1 deletions
|
@ -1,10 +1,12 @@
|
||||||
package templates
|
package templates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
|
@ -26,8 +28,24 @@ func (c context) Include(filename string) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(file)
|
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
|
// Date returns the current timestamp in the specified format
|
||||||
|
|
Loading…
Reference in a new issue