Search code examples
javascriptnode.jsexpressejscustom-element

Is it possible to embed Custom Elements in an ejs template?


I am working on a project where the main site is in ejs templates and would like to know how I might use a basic custom element of the type: class x extends HTMLElement.

I found ejs-html, but it works with custom ejs elements, not what I was looking for.

I realize this would be no problem using any other framework besides a templating engine, but the project is locked into ejs.


Solution

  • Custom Web Components are something that exist in the browser. They have a specific lifespan and would not easily translate to a server rendered component.

    Having said that, your EJS file can include the JS file needed and then you would place the element where you wanted it. But it will not render until the browser downloads the JS file.