caddy/middleware/templates/context.go
2015-04-18 09:57:51 -06:00

24 lines
518 B
Go

package templates
import (
"io/ioutil"
"net/http"
)
// This file contains the context and functions available for
// use in the templates.
// context is the context with which templates are executed.
type context struct {
root http.FileSystem
}
// Include returns the contents of filename relative to the site root
func (c context) Include(filename string) (string, error) {
file, err := c.root.Open(filename)
if err != nil {
return "", err
}
body, err := ioutil.ReadAll(file)
return string(body), err
}