[w3c/webcomponents] [templates] If HTML Template Instantiation proposal is adopted, consider a HTML-native syntax (#695)

Apple's new proposal (https://github.com/w3c/webcomponents/blob/gh-pages/proposals/Template-Instantiation.md) is intriguing and I think worth supporting. They explicitly do not endorse any specific template syntax though, which is understandable.

The decision as to which template syntax to standardize on is certainly a tough question, given how many competing syntaxes exist.

I think there is a decent case to be made though that an objectively best syntax would be one that is quite *unlike* most popular templating systems - instead favoring a syntax that is grammatically native to HTML.

Consider something like this (rough) example:

```html
<template>
  <p>hello world</p>
  <if variable>
    <p>{variable}</p>
  </if>
  <else>
    <p>the variable is not populated!</p>
  </else>
</template>
```

Assuming a JSON model consisting of `{variable: 'dynamic data!'}` is populated, the template, when parsed, renders as:

```html
<p>hello world</p>
<p>dynamic data!</p>
```

If the variable were removed from the model, the if statement in the template would return false and the second `<p>` tag would contain the alternative content "the variable is not populated!" instead.

Imagine also an `<include>` tag for layout templates and partials which accepts arguments via child `<arg>` elements and a full suite of flow control tags in addition to `<if>` and `<else>` like `<unless>`, `<elseif>`, and `<elseunless>` for basic templating logic, and of course a `<loop>` tag for looping.

Such a standard as this strikes me as much more in the spirit of HTML than standardizing on any of the popular mainstream templating languages that are out there, specifically because all the others are their own languages whereas a proposal such as this is just new HTML tags.

In fact, I felt so strongly about it that I and a few like-minded others actually [prototyped an implementation](https://github.com/rooseveltframework/teddy/) of exactly this syntax. We are not married to the specific syntactical details or tag names, and our implementation is still super rough around the edges, but you can play with it today, and we think there is real value in a templating syntax that is grammatically compatible with HTML.

Regardless of implementation details or specific tag choices, it does seem that following the grammar of HTML by sticking to `<tags>` for flow control and reserving the curly braces to `{variables}` only is an idea worth considering.

I'm not sure if this is the right place to raise a discussion such this, or if something similar has been proposed before here or elsewhere, so if this is the wrong place to discuss this, I apologize.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/695

Received on Friday, 3 November 2017 07:38:57 UTC