summaryrefslogtreecommitdiff
path: root/api/template.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/template.go')
-rw-r--r--api/template.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/api/template.go b/api/template.go
index a4ccfa8..eeaeb51 100644
--- a/api/template.go
+++ b/api/template.go
@@ -9,7 +9,7 @@ import (
"os"
)
-func renderTemplate(context *RequestContext, templateName string, showBaseHtml bool, data interface{}) (bytes.Buffer, error) {
+func renderTemplate(context *RequestContext, templateName string, showBaseHtml bool) (bytes.Buffer, error) {
templatePath := context.Args.TemplatePath
basePath := templatePath + "/base_empty.html"
if showBaseHtml {
@@ -22,11 +22,14 @@ func renderTemplate(context *RequestContext, templateName string, showBaseHtml b
return bytes.Buffer{}, err
}
- if data == nil {
- data = map[string]interface{}{}
+ dataPtr := context.TemplateData
+ if dataPtr == nil {
+ dataPtr = &map[string]interface{}{}
}
- if context.User != nil {
- data.(map[string]interface{})["User"] = context.User
+
+ data := *dataPtr
+ if data["User"] == nil {
+ data["User"] = context.User
}
var buffer bytes.Buffer
@@ -38,13 +41,13 @@ func renderTemplate(context *RequestContext, templateName string, showBaseHtml b
return buffer, nil
}
-func TemplateContinuation(path string, data interface{}, showBase bool) Continuation {
+func TemplateContinuation(path string, showBase bool) Continuation {
return func(context *RequestContext, req *http.Request, resp http.ResponseWriter) ContinuationChain {
return func(success Continuation, failure Continuation) ContinuationChain {
- html, err := renderTemplate(context, path, true, data)
+ html, err := renderTemplate(context, path, true)
if errors.Is(err, os.ErrNotExist) {
resp.WriteHeader(404)
- html, err = renderTemplate(context, "404.html", true, nil)
+ html, err = renderTemplate(context, "404.html", true)
if err != nil {
log.Println("error rendering 404 template", err)
resp.WriteHeader(500)