-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[templates] Consider ${foo} instead of {{foo}} #688
Comments
The disadvantage to choosing the same syntax as JavaScript is that it makes it more difficult to create templates as template literals in JavaScript (you have to remember to escape them all). For ex: template.innerHTML = `
<h1>\${name}</h1>
<h2>${title}</h2>
`; Would throw assuming |
I think its problematic to use fixed syntax. Programmers should able to set custom interpolation syntax. Some server side templating engines uses nearly same {{ var }} syntax and this may cause conflicts when javascript code mixed with template code. |
I don't think we want to make this configurable. That's one thing this standardization process provides: uniform templating syntax. If we're going with
|
Neither |
|
@matthewp that's an edge, just like for example creating webworker from a (blob url) string and creating <script> inside of it that also uses template strings. Yes you can do it, but very little people are going to. And if you do than prepare for the burden of escaping. We shouldn't surrender to edge cases and introduce yet another syntax and complexity to keep in mind. |
It's the problem of template engine developers, they know the css syntax and they must care about interpolation syntax for code compatibility. This situation is different. |
I see few issues here:
Note: we should not loose the focus, in my opinion, the goal of this proposal to provide a high-performant way to create and updating instances of templates following the principles of EWM. Let libraries to provide the abstractions, the interpolation aspect of it, etc., and focus on the low level pieces. The template is not JS, users should not be confused, it is just HTML. |
@caridy : We wanted to support a very small subset of JavaScript without supporting arithmetic or any other kind of operators but There is no restriction on what a custom template processor could do besides the fact delimiters would always be |
One that I end up using fairly often is adding ie. |
That is my biggest concern. Is it absolutely necessary? where do you draw the line between JavaScript and the subset that you want to support? Based on historical discussions at TC39, we have seen people attempting to implement a subset of JS over and over again, no-one has succeed at that (at least that I know of), in fact, most of them ended up supporting the entire thing or disapearing. Look at handlebars for example:
I'm sure @wycats will have some strong opinions about this. If developers have a way to provide those expressions via abstractions on top of the processCallback or any other similar mechanism to evaluate the expressions, we should be fine. Lets library to compete for the best syntax, just provide the mechanism for the processing of the parts. |
See #682 for discussion of the default processor. |
At TPAC we agreed that we would not be OK moving forward with a syntax that requires escaping when using in conjunction with JS. (As demonstrated so succintly by @matthewp's #688 (comment).) Note that we weren't set on double-curlies, but single-curlies and dollar-curlies are striaght out, by this criteria. Further discussion of the default processor can be done in #682. As such, let's close this. |
Proposal: align the interpolation syntax with JavaScript.
https://github.com/w3c/webcomponents/blob/gh-pages/proposals/Template-Instantiation.md
The text was updated successfully, but these errors were encountered: