Created
October 2, 2015 21:49
-
-
Save JanMiksovsky/ef59c30222b5d5fc06b5 to your computer and use it in GitHub Desktop.
Create a Polymer element using a real <template>, not a <dom-module>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<link rel="import" href="../components/polymer/polymer.html"> | |
<template id="test-element"> | |
Hello, <content></content>. | |
</template> | |
</head> | |
<body> | |
<test-element>world</test-element> | |
<script> | |
Polymer({ | |
is: 'test-element', | |
_template: document.querySelector('#test-element') | |
}); | |
</script> | |
</body> | |
</html> |
This is great! I wish I could add an '_template' value that is a es2015 template string as well. Thanks for sharing this
Would it be worth it to create an issue for this, or somehow bring it up with the team?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Polymer's template-stamping feature can accept a regular template, not just one supplied via a
<dom-module>
. It turns out that the template can be referenced declaratively by defining a _template variable.Note: if defining the element in an HTML import, change the _template declaration to use
currentImport
, which is Polymer sugar for the current HTML import:It would be cool if Polymer supported this more formally, e.g., by dropping the underscore from _template. This would allow direct use of real templates without relying on proprietary
<dom-module>
elements.