4 ms·
Totally agree, I'm also glad there is another resource for learning templating! The gotchas are frequent for me when it comes to templating in Go. Recently I fo
by qrv3w 9y ago
Totally agree, I'm also glad there is another resource for learning templating! The gotchas are frequent for me when it comes to templating in Go. Recently I found that html/template will strip tags when inserting into an attribute [1]. I did not realize that Go made a special template for attributes (template.HTMLAttr) which is what I needed to make it work. [2]
[1]: https://play.golang.org/p/nHG_F2a0t-4 https://play.golang.org/p/nHG_F2a0t-4
[2]: https://play.golang.org/p/TU5CX9Kstj https://play.golang.org/p/TU5CX9Kstj
- hellcow 9y agoThat's not all! Try inserting a Go variable within a script tag, and Go will automatically convert it to JSON. Makes it possible to easily do this: let msgs = {{ .Messages }} Where .Messages is any slice. Same is true for structs -> JS objects.