According to this open ticket (https://github.com/Polymer/polymer/issues/1976), you actually CAN have a template element nested inside an svg element. The fix I will link to below is a port of the code from 0.5. The issue is described in detail here and in the open ticket, so no need to go over it again.
Important:
If you would like to indicate to Google and the polymer team that this is indeed an important feature, please make sure you leave a comment on the ticket.
- It does give the intended functionality back in polymer 1.0.
- It is required to be included at the top of the .js file of each web component which may use it.
- It also assumes a specific html structure (which you will see below).
- It only works in chrome right now.
Snippet: https://gist.github.com/bendavis78/15528ca2f501c44f2fa4
foo-svg.css
foo-svg svg {
border: 2px solid yellowgreen;
fill: transparent;
height: 400px;
width: 400px;
}
foo-svg.html
<dom-module id="foo-svg">
<link rel="stylesheet" href="foo-svg.css"/>
<template>
<svg class="clock" version="1.1" xmlns="http://www.w3.org/2000/svg">
<template is="dom-repeat" items="{{positions}}" as="cx">
<circle cx$="{{cx}}" cy="25" r="25" stroke="black" />
</template>
</svg>
</template>
<script src="foo-svg.js"></script>
foo-svg.js
(function () {
// START HACK
var doc = document.currentScript.ownerDocument;
var root = doc.querySelector('dom-module > template').content;
var templates = root.querySelectorAll('svg template');
var el, template, attribs, attrib, count, child, content;
for (var i=0; i<templates.length; i++) {
el = templates[i];
template = el.ownerDocument.createElement('template');
el.parentNode.insertBefore(template, el);
attribs = el.attributes;
count = attribs.length;
while (count-- > 0) {
attrib = attribs[count];
template.setAttribute(attrib.name, attrib.value);
el.removeAttribute(attrib.name);
}
el.parentNode.removeChild(el);
content = template.content;
while ((child = el.firstChild)) {
content.appendChild(child);
}
}
// END HACK
Polymer({
is: 'foo-svg',
properties: {
paths: {
type: Array,
value: []
}
},
ready () {
this.positions = [0, 100, 200, 300];
}
});
})();