Re: [w3c/webcomponents] [templates] Template proposal essentials (shave the mustache) (#739)

Let's discuss this part here.

It would not break down with nesting templates or logic. Symbol `$$` should not be a part of the spec (we don't want to introduce any new syntax), it was just an example how developer can write flat templates and turn them into **array of strings**.

We won't have simple string replacement, rather we will have a mechanism (based on build in HTML parser) that **turn that array of strings into DocumentFragment and Parts object**.

So if you ask where all the logic and nesting should go then? The answer is to javascript through template strings e.g.
```js
const template = html`
  <div>
    <h1>${name}</h1>
    ${name ? html`<h2>Wellcome ${name}!</h2>` : ''}
  </div>
`
```

As you see we have nesting template and `if` logic here and `html` tag that will receive that **array of strings and turn it into a DocumentFragment and Parts object**.

More specifically the inner template will receive plain (string) name value as a part value, while the outer template will receive inner template as a part value. So there is no issues when we are substituting string or DocumentFragment into a template (very naive implementation could use innerHTML as in example of the original post, smarter - will take care of context, but it is still very native to substitute DocumentFragment into another DocumentFragment).

This way we might have very descriptive templates with all familiar js syntax, while keeping proposal small. As a result we will be able to write templates in js (with template strings) and html (developer will introduce a preferred separator and have only plain template that he will split into **array of strings**, more complex template logic and composition should be done in js part through the template strings)

-- 
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/739#issuecomment-367222958

Received on Wednesday, 21 February 2018 06:03:18 UTC