http://jsbin.com/zadejogide/1/edit?html,output
this fiddle works.
this does not directly answer your question but it explains what happens.
if you nest "my-element" into antoher element, the Light DOM of that element is hidden in the shadow tree of the outer element (in this case "my-test") which means: the template tag cant find it.
possible solution
you could adopt the template and append it to the shadowRoot of "my-element" (In some way the template recognize the shadowRoot in which it participates but no others) like here Using template defined in light dom inside a Polymer element (dynamic template creation)
or try this one with is="auto-binding".
<polymer-element name="my-element">
<template>
<template id="template" is="auto-binding" ref="foo">
should not get displayed
</template>
</template>
<script>
Polymer('my-element', {
domReady: function() {
var foo = this.querySelector('#foo');
if(foo){
this.shadowRoot.appendChild(foo);
}
}
});
</script>
</polymer-element>
both approaches dont "really" answer your question but they are acceptable workarouns for this situation.
i also tried to set the ref_ property of the template in javascript but without success... and poking on the private members is not really a good practice.