- From: Brian Kardell <bkardell@gmail.com>
- Date: Tue, 24 Apr 2012 12:11:40 -0400
- To: Erik Arvidsson <arv@chromium.org>
- Cc: Rafael Weinstein <rafaelw@google.com>, Ryosuke Niwa <rniwa@webkit.org>, Yuval Sadan <sadan.yuval@gmail.com>, public-webapps <public-webapps@w3.org>
On Tue, Apr 24, 2012 at 11:48 AM, Erik Arvidsson <arv@chromium.org> wrote: > On Tue, Apr 24, 2012 at 06:46, Brian Kardell <bkardell@gmail.com> wrote: >> I know of many, many templating systems and I have simply never (aside >> from MDV) seen it in exactly this light (that is templates actually >> embedded in others), regardless of whether those are for within the >> browser for generating HTML (or anything else) or on the server - or >> even for code generation. It seems to me that there is a rich history >> of templating text, it's very useful and in every case I have seen you >> have "a template" and that template can contain references to other >> templates, not embed them... Am I seeing this improperly? This seems >> to be the case with freemarker, velocity, mustache, handlbars, even >> jsp, asp, php, etc - (there are really a lot of them, I'm just >> throwing out a bunch). This kind of approach does not seem like it >> would be out of place in HTML or even XML - we think about a lot of >> things that way (in terms of references). Are there some in >> particular that someone could point to that illustrate otherwise? > > Most system do allow it. The syntax they use might not make it clear. > > http://emberjs.com/#toc_displaying-a-list-of-items > > <ul> > {{#each people}} > <li>Hello, {{name}}!</li> > {{/each}} > </ul> > > In here there is a template between the start each and end each. While you could think of it that way, that's not generally how we refer to it when discussing templates - right? Just pick any and the documentation (it seems to me) will refer to "templates" separately from instructions/macros/etc that make up the templating language (the above are an example of handlebars each block helpers). In your provided example (which uses handlebars) the better analogy to what I am arguing is partials - see https://github.com/wycats/handlebars.js/ --- about 1/2 way down the page you will find: Partials You can register additional templates as partials, which will be used by Handlebars when it encounters a partial ({{> partialName}}). Partials can either be String templates or compiled template functions. Here's an example: var source = "<ul>{{#people}}<li>{{> link}}</li>{{/people}}</ul>"; Handlebars.registerPartial('link', '<a href="/people/{{id}}">{{name}}</a>') var template = Handlebars.compile(source); var data = { "people": [ { "name": "Alan", "id": 1 }, { "name": "Yehuda", "id": 2 } ]}; template(data); // Should render: // <ul> // <li><a href="/people/1">Alan</a></li> // <li><a href="/people/2">Yehuda</a></li> // </ul> Again, all of these templating systems (it seems to me) draw a distinction between these two ideas... Am I missing something?
Received on Tuesday, 24 April 2012 16:12:14 UTC