Browse Source

add jsonMarshal tpl func

main
710leo 1 year ago
parent
commit
ec7c72d68c
2 changed files with 10 additions and 0 deletions
  1. +9
    -0
      pkg/tplx/fns.go
  2. +1
    -0
      pkg/tplx/tplx.go

+ 9
- 0
pkg/tplx/fns.go View File

@@ -1,6 +1,7 @@
package tplx

import (
"encoding/json"
"errors"
"fmt"
"html/template"
@@ -653,3 +654,11 @@ func BatchContactsAtsInFeishuEmail(arr interface{}) template.HTML {
func BatchContactsAtsInFeishuId(arr interface{}) template.HTML {
return template.HTML(MappingAndJoin(arr, "<at id=\"", "\"></at>", " "))
}

func JsonMarshal(v interface{}) template.HTML {
json, err := json.Marshal(v)
if err != nil {
return template.HTML("")
}
return template.HTML(string(json))
}

+ 1
- 0
pkg/tplx/tplx.go View File

@@ -61,6 +61,7 @@ var TemplateFuncMap = template.FuncMap{
"mappingAndJoin": MappingAndJoin,
"batchContactsAtsInFeishuEmail": BatchContactsAtsInFeishuEmail,
"batchContactsAtsInFeishuId": BatchContactsAtsInFeishuId,
"jsonMarshal": JsonMarshal,
}

// NewTemplateFuncMap copy on write for TemplateFuncMap


Loading…
Cancel
Save