Add function "fromhtml" for Go templates
authorMikael Berthe <mikael@lilotux.net>
Mon, 24 Apr 2017 22:30:07 +0200
changeset 14 da2059f2fa6a
parent 13 f862af8faf17
child 15 8ac069eaa817
Add function "fromhtml" for Go templates Example (for a status): {{.content | fromhtml}}
printer/templateprinter.go
--- a/printer/templateprinter.go	Sun Apr 23 23:32:16 2017 +0200
+++ b/printer/templateprinter.go	Mon Apr 24 22:30:07 2017 +0200
@@ -26,7 +26,7 @@
 // For TemplatePrinter, the option parameter contains the template string.
 func NewPrinterTemplate(option string) (*TemplatePrinter, error) {
 	tmpl := option
-	t, err := template.New("output").Parse(tmpl)
+	t, err := template.New("output").Funcs(template.FuncMap{"fromhtml": html2string}).Parse(tmpl)
 	if err != nil {
 		return nil, err
 	}