Skip to content

Commit

Permalink
Fix template compilation check on CRUD.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jul 9, 2022
1 parent 3f5a50f commit 0574a1b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"errors"
"html/template"
"net/http"
"regexp"
"strconv"
Expand Down Expand Up @@ -129,14 +130,19 @@ func handleCreateTemplate(c echo.Context) error {
return err
}

var f template.FuncMap

// Subject is only relevant for fixed tx templates. For campaigns,
// the subject changes per campaign and is on models.Campaign.
if o.Type == models.TemplateTypeCampaign {
o.Subject = ""
f = app.manager.TemplateFuncs(nil)
} else {
f = app.manager.GenericTemplateFuncs()
}

// Compile the template and validate.
if err := o.Compile(app.manager.GenericTemplateFuncs()); err != nil {
if err := o.Compile(f); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}

Expand Down Expand Up @@ -175,14 +181,19 @@ func handleUpdateTemplate(c echo.Context) error {
return err
}

var f template.FuncMap

// Subject is only relevant for fixed tx templates. For campaigns,
// the subject changes per campaign and is on models.Campaign.
if o.Type == models.TemplateTypeCampaign {
o.Subject = ""
f = app.manager.TemplateFuncs(nil)
} else {
f = app.manager.GenericTemplateFuncs()
}

// Compile the template and validate.
if err := o.Compile(app.manager.GenericTemplateFuncs()); err != nil {
if err := o.Compile(f); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}

Expand Down

0 comments on commit 0574a1b

Please sign in to comment.