Skip to content

Commit

Permalink
Add JSON-Function for Templates (muesli#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrauser authored and Mark-Jung committed May 15, 2019
1 parent abc4184 commit f0a1a85
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions templatehelper/templatehelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
package templatehelper

import (
"encoding/json"
htmlTemplate "html/template"
"regexp"
"strings"
"text/template"
Expand All @@ -30,6 +32,10 @@ import (
// FuncMap contains all the common string helpers
var (
FuncMap = template.FuncMap{
"JSON": func(values ...interface{}) htmlTemplate.JS {
json, _ := json.Marshal(values)
return htmlTemplate.JS(json)
},
"Left": func(values ...interface{}) string {
return values[0].(string)[:values[1].(int)]
},
Expand Down

0 comments on commit f0a1a85

Please sign in to comment.