fix: add json template function for post-deploy data embedding
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -324,6 +325,11 @@ func (s *Server) templateFuncMap() template.FuncMap {
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// json marshals a value to JSON for embedding in <script> blocks.
|
||||||
|
"json": func(v interface{}) template.JS {
|
||||||
|
b, _ := json.Marshal(v)
|
||||||
|
return template.JS(b)
|
||||||
|
},
|
||||||
// pageMatch returns true if currentPage is in the pages slice.
|
// pageMatch returns true if currentPage is in the pages slice.
|
||||||
// Used to filter page-specific alerts in layout.html.
|
// Used to filter page-specific alerts in layout.html.
|
||||||
"pageMatch": func(pages []string, currentPage string) bool {
|
"pageMatch": func(pages []string, currentPage string) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user