As someone who started programming with PHP, you would think that templating would be a pretty essential part of my web development life. The fact is nothing is farther from the truth. While I was a big XSLT user for a time, that was more a function of my day job and wanting to learn more than necessarily having a passion for declaratively programming the elements that would render a page. Even now, as I find myself more and more involved in writing Javascript than actual server side code, templates seem more a hindrance than help.
That is probably a bit strong. A good template language is very helpful as a gateway between programming language data structures and the intended output. The problem with template languages is not that they lack features or have odd syntax. The real issue is that it is difficult to understand the best practices or design patterns that make the best use of the templates.
The best example I have of this is the question of whether to include or inherit. On the one hand, you might have a template that includes different templates, that in turn might include other templates. The initial page might be very simple, although through including other templates, a complex feature rich page is created. Some people feel this is too unstructured since there is really no rhyme or reason to how things are included. Another option is to allow templates to inherit from larger, more generalized templates. In this way you have a more programmatic means of building pages. It might be slightly more front loaded in terms of design since you usually have to modularize the templates sooner, but that is simply part of the trade off.
Honestly, I think both methods are valid in terms of template language features. You can establish a layout and design in a way that is flexible and allows making sweeping changes or small updates. At least that is the impression I get. Like I said, the issue I find is not necessarily in the template features (or lack there of), but the actual layout patterns.
Hopefully it is clear that a simple header, footer, body layout with some columns is pretty trivial. Heading back to the land of Javascript and building modular widgets or components or whatever else you might call them (jQuery plugins), there is a question of how to properly introduce not only modularlized templates, but an efficient and simple way of also including their respective Javascript. Oh yeah, we'll throw things like CSS, Flash and any extras like custom meta/link tags in the HTML head section as well.
Obviously folks have been dealing with these concepts for as long as there has been web development. My question then is why have we not seen more frameworks or tools that help to provide an answer for these questions? Providing an answer myself, it is because there are no real best practices people want to commit to. This might be because it is hard enough to get a HTML interface working reliably in a cross browser environment, so why waste any more time. The real answer I think lies in the lack of communication regarding what is really needed in template languages and Javascript.
With that in mind, here is my rough and probably wildly wrong idea for a few tools that a template language could provide that might help improve the state of the art.
Template Parts
This entirely generic term is meant to express the idea of nesting templates in a way that is more than simply inclusion or inheriting. The problem with the current pattern is you have to include one template where you might really want to include a sequence of the same template providing different arguments. This is pretty much a "duh" kind of request, but I've yet to see something like:
template.header.push('head/javascript.tmpl', {'src': '/path/to/widget.js'})
The idea is that you could define the "header" attribute to organize your list of templates however you'd like. This might also do something as simple as appending to a single Javascript file served with a highly cacheable minted URI as well. Who knows.
Efficient Modules
Again, another super generic term that alludes to a subtle lack of understanding on my part. One problem with templates is that they often rely on external pieces to be correctly used. For example, most of the time web frameworks and the like default to using a "text/html" content type. What happens is when they return "text/plain" or "application/json" is that the method/object/etc. that handles the response must set the correct content type. XSLT does things correctly here by allowing the output tag that define the media type. It might seem a little nit picky, but the impact of concept is farther reaching then one might expect, especially when you are talking about making a template more efficient.
Again, a method that returns a response will often times returned that response in chunks or in one piece. It would be great if you could do similar things with templates. Some templates need to understand an entire template while others work as a streaming filter. Most template languages don't necessarily allow ultra fine grained control of this sort of thing. What's more, they most definitely don't allow the template to define this kind of attribute. I don't blame template language authors since this would probably end up making a mess of things in terms of complexity. That said, it would be nice to define within a template whether it was "streamable" or not. Likewise, it would be also be nice to declare within the template the content type if necessary. In these kinds of situations you might have a streamable template that outputs a CSV content type. Another example is a single Javascript file that must be in the correct order. There are other tools that help with different aspects of this kind of problem, but letting the template define these bits might help to move some details into the template where it arguably belongs.
Normalized Data Environment
This is just a really terrible name for being able to easily provide a template with some JSON as the variable environment and return the result. Pretty simple stuff. It has probably been done a million times in one way or another but it seems helpful. One gotcha is that often times people will pass in things like database connections to a template. This is totally fine as long as the objects allow specific operations. The best example of this is iteration and in fact I can't really even think of another off hand, so I'll stop there. This last bit is probably a little outside the scope of a template language need and would probably fall into the realm of a tool or framework. In any case, the idea is to provide a reliable means of encapsulating templates, most obviously for things like Ajax.
Like I said, these ideas are probably somewhat incorrect and it wouldn't surprise me template language authors simply laugh at these suggestions. But if that is the case, then I'd say it might very well be up framework writers to establish the best practices and potentially integration with specific template languages. It would be really nice to have a "MakoNiceSite - The Effective Mako Toolkit" or some other collection of tools that make common Mako patterns more obvious. Also, it seems reasonable to have a few other dependencies such as a CSS framework. I've been using the YUI CSS tools and while I'm sure there are some caveats to be aware of, the constraints have been helpful and faster to develop with.
In the end it would be really great if there was a HTML on Rails kind of system that makes things like modular templating simple. The pieces all seem to be present, it is just a matter of putting them together that seems so difficult.