Polymer 3 - Is there way to extract the html template into a separate html file?

109 views
Skip to first unread message

meatp...@gmail.com

unread,
Sep 5, 2018, 4:35:39 AM9/5/18
to Polymer
Hi there,

i'm still confused. I try to extract the html template from my polymer component into a standalone html file. For polymer 2 i found some examples, but they don't work for my polymer 3 project. I tried something like the following, but it fails.

import * as template from './pm.template.html';
....
static get template() {
return template;
}


So as simple question, it is possible to separate the template as html file (not a js file)  & if yes, how?

Thanks for your help

ciao Torsten

Mark

unread,
Sep 5, 2018, 8:07:19 AM9/5/18
to meatp...@gmail.com, Polymer
Possibly, but the short answer is no. There is currently no way to statically import html content into a js file natively. It will need to be a js file that exports your html template. 

I suspect you could write your own custom build step to transpile the contents of an html file to a template, but that may be more trouble than its worth if there isnt already a package for it.

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/b21b72ed-ff8f-4dcf-a779-33ccdb192674%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

to...@starcounter.com

unread,
Sep 5, 2018, 10:07:07 AM9/5/18
to Polymer
You may find following discussions interesting 

There are ideas to make it a Web standard.

Regards,
Tomek

su...@firsov.net

unread,
Oct 25, 2018, 12:34:05 PM10/25/18
to Polymer
While in Polymer directly it has some troubles, webpack actually gives some options for that: https://github.com/webpack-contrib/html-loader
Or alternatively you could use lazy dynamic content loading via EPA-WG/embed-page
static get template()
{
   
return html`<embed-page  src="templateA.html" scope="none" ></embed-page>`;
}
Reply all
Reply to author
Forward
0 new messages