4 ms·
> "html/template" doesn't support things like inheritance I don't want to get into a debate about what "inheritance" means, but html/template does support temp
by chimeracoder 13y ago
> "html/template" doesn't support things like inheritance
I don't want to get into a debate about what "inheritance" means, but html/template does support template composition and nested templates, which seem to address the same use case.
> These two problems have made it so I've pretty much given up web apps in Go for now. Services in Go are _amazing_. But if you're trying to get a full blown web app (again, not the point of the linked article above), then you're gonna have a bad time.
I'm sorry to hear that, especially since writing a "full-blown web app" is really not difficult in Go at all, once you know what you're doing.
I've actually been working on Jetpack[0], a sample web application in Go to demonstrate how straightforward this is, once one understands how it actually works. (Disclaimer: it's still a work in progress, so it's not complete/ready yet).
[0] https://github.com/ChimeraCoder/go-angular-jetpack https://github.com/ChimeraCoder/go-angular-jetpack
- BarkMore 13y agoThe html/template package seems to address the use case, but it comes up short in several ways. One example is defining a site template with sections that are optionally specified in a page specific template.
- memset 13y agoMany of your comments on this thread state that writing webapps in Go (SQL, etc) is not so difficult "once you know what you're doing." Could you elaborate on this? What should one know before attempting to use Go for such things?
- unoti 13y agoHere's one possible example. At the top of this thread, there's a statement about how Go templates don't support inheritance-- embedding one template within another as Django and Jinja do[1]. I personally consider this a requirement, because the old school way of having headers and footers in separate templates is radically inferior. Go doesn't offer a clear simple way to do this in their builtin template library. But it turns out, it really is possible to do it, as described in this thread on Stack Exchange[2]. I bookmarked that so that I can boil it down into some simple-to-reuse code if I ever bite the bullet and start using Go for the presentation layer on a major website. What they're doing there is a cool technique, but it's not simple to use out of the box. 1. https://sites.google.com/site/usfcomputerscience/django-templates https://sites.google.com/site/usfcomputerscience/django-temp... 2. http://stackoverflow.com/questions/11467731/is-it-possible-to-have-nested-templates-in-go-using-the-standard-library-googl http://stackoverflow.com/questions/11467731/is-it-possible-t...
- zemo 13y agothe problem with html/template is that it's made for Go programmers. A good template language is one that's made for front end devs and designers. html/template tends to be painful in practice because it's too difficult for a non-gopher to use.
- chimeracoder 13y agohtml/template is literally nothing more than an "HTML-safe" version of text/template, which is Go's arbitrary text template language. It's meant to be completely a drop-in replacement for text/template, and as such, its design does not give HTML output any special consideration, which an HTML-specific template language would. I understand the point you're making - I just want to point out that Haml is explicitly designed for HTML, whereas html/template more or less "just happens" to be useful for HTML. As for ERB, I'm not convinced that it is too different in this regard. I'm not much of a Rubyist, and I find it incredibly frustrating to use, but perhaps that's a matter of personal preference. {text,html}/template have their warts - I literally started Jetpack because of an unusual html/template quirk I ran into that was tricky to debug. However, I don't think it's any worse than other template language in this regard (my main points of reference are Jinja2, ERB, Haml, and Scribble).
- MetaCosm 13y agoIt is context aware, which is actually really awesome! It understands if it is in a tag, in a script, in quotes, in double quotes, in source, in css, in style and lots of stuff I am forgetting and does the custom escaping required to make it safe for that context. That is freaking magical.