2 ms·
> I don't get why textual templates are so popular […] you can't open a tag in a subtemplate and close it in another one but I think you can see that as a featu
by sorbits 14y ago
> I don't get why textual templates are so popular […] you can't open a tag in a subtemplate and close it in another one but I think you can see that as a feature
For many, it’s frustrating having to work with a model where you can’t split up your template into multiple parts, without needing to make each part a valid document on its own.
E.g. a blog would have templates for the page header/footer and article header/footer.
It’s trivial to output the page header template, then iterate over the articles and output the article header/footer around the article text, which may be piped through various filters, and finally the page footer template.
I think we can all imagine how such system looks when the templates are “raw text” (perhaps with some special tags for placeholders).
I am interested in seeing how it will look if we are to use a document-oriented template language, as I certainly do like the idea of it, but I think in practice it adds overhead and restrictions, which doesn’t make the extra safety worth it.
- nightpool 14y agoWhy not just use a sub-template model then? Where you have a "page" template that includes the "header", "content" and "footer" template, possibly even decided at runtime?
- sorbits 14y agoSuch solution require much of the page-building logic (loops, conditions) to be moved into the template language, and the state transfer that goes with it. This means trivial tasks require editing multiple files, e.g. say we introduce pagination: the master template now need to be told by the controller, if it should include the “page n of m” template. I assume ufo avoids this problem (and the limited capabilities of template languages wrt. logic) by instead using host language libraries to generate the HTML, but IMO that has the downside of limited interoperability, as the templates are then just code written for some library.
- ufo 14y agoIf you really want to be able to split the document like that you can use a more "document streaming model", SAX-style, with separate functions for opening and closing the tags. What really matters is that the system knows what tags and attributes are so if can do things like quote attributes for you, check that closing tags match correctly and so on. (saying forcing complete subtemplates is a feature might have been too strong of a language, but I don't think its that big of a deal since you can usually work around it by splitting things up a bit) As you said, the real advantage of text-based systems is that they can generate text in other languages (sql, configuration files, etc) and that its easier to interoperate with other tools that spit out raw output. However, I fell things get really kludgy when you try to add automatic escaping to the text-based systems, for the reasons outlined in the original article.