-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Supply html
tag function for generating template in modules
#4937
Comments
I presume we'd hang this tag directly off the To trigger syntax highlighting in editors, we'd probably need a pattern like: const html = Polymer.html;
class SuperClass extends Polymer.Element {
template = html`...`;
} |
Eh, I don't really think anyone should bother using it unless they're using 3.0, where it's not an issue because they're importing it. But yeah, we'd hang it on |
Ah, good point |
Is lit-html usable with Polymer 3 at this point? |
@Hadrian this issue isn't related to lit-html. It's just about adding a template tag in Polymer to create Polymer HTML templates and trigger syntax highlighting. |
Description
Currently
static get template()
can return anHTMLTemplateElement
or a string which is internally parsed into a template. When moving to modules in Polymer 3, all templates fromdom-modules
are automatically moved into strings returned from the static template getter bymodulizer
, and all newly authored elements would be expected to just return strings. This will be problematic for any Polymer 2.0 elements that extended an element and usedsuper.template
to wrap/modify its super class template assuming super.template returned anHTMLTemplateElement
.As such, we propose to deprecate
Polymer.Element
's support forstatic get template()
returning strings, such thatsuper.template
is guaranteed to return anHTMLTemplateElement
, and never a string. In its place, we'll provide ahtml
tagged template literal tag function that does the string -> template conversion, and modulizer will be changed to wrap template strings withhtml
automatically.This approach solves both the backwards-compatibility problem mentioned above, eliminates the ambiguously-typed nature of the current
template
API, and also has an extra benefit of providing a hint to code editors to syntax-highlight the template string as HTML (Sublime, Atom, and Github apparently already do this automatically, and VS Code has a plugin to do so).In addition, the
html
tag function should have a small amount of sugar to allow creating holes in the template, so that subclassers can override those withhtml
-tagged strings (which return templates) and have the hole values interpolated as strings (viainnerHTML
) before being converted to a template, e.g.:Super class (provides a template with header and footer "holes"):
Sub-class (both wraps the super template, and overrides the header/footer "holes"):
To make the examples above work, the
html
tag function must take theinnerHTML
of any interpolated values that areHTMLElement
s; this is the only sugar proposed, other than taking the final interpolated string and parsing it into a newHTMLTemplateElement
.Note, the
html
tag function described here to be shipped with Polymer (which simply returns a vanillaHTMLTemplateElement
) should not be confused with thehtml
tag function provided with thelit-html
library, which is similar in concept but separate in implementation. I think the benefits of de-facto standard HTML syntax highlighting in editors outweighs the potential confusion.Versions
The text was updated successfully, but these errors were encountered: