From ad08a1011dd7463e8a8d7adfade4fb69452f29e8 Mon Sep 17 00:00:00 2001 From: herkulessi Date: Mon, 29 Dec 2025 18:31:03 +0100 Subject: Add Raw Template Function without HTML Escaping --- templates.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/templates.go b/templates.go index 00c1b31..408085c 100644 --- a/templates.go +++ b/templates.go @@ -7,6 +7,7 @@ import ( "html/template" "io/fs" "net/http" + texttemplate "text/template" ) type templates struct { @@ -68,3 +69,14 @@ func (w *Webpage) RenderTemplateToString(name string, data any) string { } return buf.String() } +func (w *Webpage) RenderTemplateToStringUnescaped(name string, data any) string { + buf := bytes.NewBuffer(nil) + tmpl, err := fs.ReadFile(w.getTemplateRoot(), "templates/"+name+".tmpl") + if err != nil { + panic(err) + } + if err := texttemplate.Must(texttemplate.New("templates/"+name+".tmpl").Funcs(w.templates.bindings).Parse(string(tmpl))).Execute(buf, data); err != nil { + panic(err) + } + return buf.String() +} -- cgit v1.2.3