diff --git a/pkg/tplx/fns.go b/pkg/tplx/fns.go index 7e1903db..dacdfea2 100644 --- a/pkg/tplx/fns.go +++ b/pkg/tplx/fns.go @@ -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, "", " ")) } + +func JsonMarshal(v interface{}) template.HTML { + json, err := json.Marshal(v) + if err != nil { + return template.HTML("") + } + return template.HTML(string(json)) +} diff --git a/pkg/tplx/tplx.go b/pkg/tplx/tplx.go index 3a1f51ea..e56b4762 100644 --- a/pkg/tplx/tplx.go +++ b/pkg/tplx/tplx.go @@ -61,6 +61,7 @@ var TemplateFuncMap = template.FuncMap{ "mappingAndJoin": MappingAndJoin, "batchContactsAtsInFeishuEmail": BatchContactsAtsInFeishuEmail, "batchContactsAtsInFeishuId": BatchContactsAtsInFeishuId, + "jsonMarshal": JsonMarshal, } // NewTemplateFuncMap copy on write for TemplateFuncMap