Here's a custom element that does something similar.
Polymer({
is: 'bind-ref',
properties: {
ref: {
type: String,
observer: 'refChanged',
},
},
refChanged: function(newRef, oldRef) {
if (oldRef != undefined) {
this._removeChildren();
this._stamp();
}
},
_stamp: function() {
this._parent = Polymer.dom(this).parentNode;
var rootEl = this._parent;
while (Polymer.dom(rootEl).parentNode) {
rootEl = Polymer.dom(rootEl).parentNode;
}
var tpl = Polymer.dom(rootEl).querySelector('#' + this.ref);
var tplRoot = tpl.stamp().root;
this._children = Array.prototype.slice.call(tplRoot.childNodes);
Polymer.dom(this._parent).insertBefore(tplRoot, this);
},
_removeChildren: function() {
for (var i = 0; i < this._children.length; i++) {
Polymer.dom(this._parent).removeChild(this._children[i]);
}
},
attached: function() { this._stamp(); },
detached: function() { this._removeChildren(); },
});
The target template element must be a dom-template
element.
<bind-ref ref="howdyTpl"></bind-ref>
<template is="dom-template" id="howdyTpl">Howdy <span>{{whatever}}</span></template>
(Code snippets licensed Apache 2.0.)