3 ms·
They are woefully undocumented. Well, that perhaps isn't fair... fairer would be to say that there isn't an authoritative set of examples showing how people ca
by buro9 11y ago
They are woefully undocumented.
Well, that perhaps isn't fair... fairer would be to say that there isn't an authoritative set of examples showing how people can achieve things similar to something like Django templating or Rails templating. It is actually fairly effortless to nest templates, extend them with custom functions, and all of the things one would need to do.
Probably one of the best resources is Hugo: https://gohugo.io/templates/go-templates/ https://gohugo.io/templates/go-templates/ and the funcs (template tags) they ship.
That isn't too bad at all, but the snippets and examples are so small that it's hard to really see what the value is and how it all glues together to create nice readable templates.
Anyhow, the key place to look at template tags would be:
1. Hugo's source code for template funcs: https://github.com/spf13/hugo/blob/master/tpl/template_funcs.go https://github.com/spf13/hugo/blob/master/tpl/template_funcs...
2. Hugo's creation of the func map: https://github.com/spf13/hugo/blob/master/tpl/template_funcs.go#L1644 https://github.com/spf13/hugo/blob/master/tpl/template_funcs...
3. Hugo's documentation on the funcs: https://gohugo.io/templates/functions/ https://gohugo.io/templates/functions/
Those three things, viewed as one, should allow any Go dev to extend templates to do whatever you want them to do.
Hugo have been very "functional" in their choice of template tags, but there's huge scope for new packages to deliver more aesthetic tags, or tags for localization, to humanise time and plurals, basically to provide a core resource of tags similar to https://docs.djangoproject.com/en/1.9/ref/templates/builtins/ https://docs.djangoproject.com/en/1.9/ref/templates/builtins... so that each dev doesn't implement their own.