An additional tip. Template actions don't necessarily have to be delimited by '{{' and '}}'.<p>Before parsing, you can call Delims to use custom delimiters.<p><pre><code> func (t *Template) Delims(left, right string) *Template
</code></pre>
<a href="https://golang.org/pkg/text/template/#Template.Delims" rel="nofollow">https://golang.org/pkg/text/template/#Template.Delims</a>
I really want to love templates, but I find many aspects to be quite confusing.<p>(1): I just want to deploy a binary file. This does not seem possible with templates (unless they're defined inside .go files, but never seen anyone do that).. also rather annoying that the tmpl files must be located in a specific directory rather than located among their components.. but I guess it wouldn't make much sense anyway since they won't be a part of the binary file.<p>(2): it's really difficult to find good and medium-large scale projects that are using templates<p>(3): I have no idea what's the right way to initialize and execute templates, this includes when the same template will be called in multiple funcs. I know how I can do it, but I don't feel confident that I'm doing it correctly..<p>(4): it's really exhausting to keep template code clean. With Go (and various JS frameworks) the code is automatically formatted/linted/whatever, but with templates nada.. can't even figure out how to minimize it for production.<p>(5): no idea what to do with css/js.. sometimes use inline, other times call a static file. Static files obviously benefit from being cached.. not sure how I'm supposed to cache the templates<p>I can't really tell if there are any speed gains to using templates, so it feels like a lot of sacrifices for no obvious gain. I do think templates would be godlike if they featured vue-like structure with "template/script/style" syntax, and was easily minified and compiled into the binary. But I guess I can keep dreaming about the last part :)
This Django style template library is also quite slick: <a href="https://github.com/flosch/pongo2" rel="nofollow">https://github.com/flosch/pongo2</a>
I am also really glad someone has glued toghether major aspects of template/html std library. It is definetely a place where are some 'taboos', tricks or gotchas, i.e. re-usability of tmpl static variable to add multiple named templates and call them by name (re: question on disqus below article) or sharing parent scope to children variable when using range loop (stackoverflow popular question). I am bit sad I haven't found some free time to collect all known 'tricks' to me and try to list them somehow or send CR yet.
Have you tried to benchmark writing out a page with Go templates, vs GO producing a JSON API that prints out into static HTML pages with JQUERY/Handlebars? How many RPS can you get with either scenario? What is Time to First Paint and when does the page finish printing for the user?