Partial solution: works below in chrome, but not polyfill browsers (for example, firefox). You need to look at the polyfill code to figure out how to handle links in an already linked file.
The problem is that the contents of the import are not inserted into the document, but simply become available for use. See HTML5 Importing stones - using content for more details. You can find all the templates in the linked file and paste them into your fragment of the polymer element document:
var importDoc = document.currentScript.ownerDocument; var link = importDoc.querySelector('.myimports'); var templates = link.import.querySelectorAll('template'); for (var i=0;i<templates.length;i++) { importDoc.head.appendChild(templates[i]); }
Example
demo templates.html
<template id="hello">Hello World!</template> <template id="goodbye">See you tomorrow</template>
demo importTemplates-list.html
<link class="myimports" rel="import" href="demo-templates.html"> <polymer-element name="demo-importTemplates-list"> <template> <template repeat="{{ li in data }}"> <h1>{{li}}</h1> <template bind ref="hello"></template> -- <template bind ref="goodbye"></template> </template> </template> <script> Polymer({ data: ['first','second','third'] }); </script> </polymer-element>
index.html
<html lang="en"> <head> <script src="../../webcomponents/bower_components/webcomponentsjs/webcomponents.min.js"></script> <link rel="import" href="../../webcomponents/bower_components/polymer/polymer.html"> <link rel="import" href="demo-importTemplates-list.html"> <title>demo-importTemplates</title> </head> <body> <demo-importTemplates-list type="hello"></demo-importTemplates-list> </body> </html>
source share