CodeCoupler Webpack Import EJS Templates
If you need to write an EJS template, you can use the extension *.ejs.html
or *.template.html.
Files ending in *.ejs.html will be parsed by the package ejs. Files ending in
*.template.html will be parsed by the underscore function template.
Then, you can use variables such as <%= locals["some-var"] %> in your template. All HTML templates
will be included in the final JavaScript bundle.
In your JavaScript file, require the templates and submit the properties of the variable data like
this:
Linked Assets
To link assets such as images, you must use the following syntax:
The filename must start with ./.
Nested Templates
To use the include methods of EJS you have to pay attention to the following:
If you are using the ejs parser, you cannot use the include() function. Instead, you must use
the include preprocessing statement:
If you are using the template() function, you must include the content from variables, as
described here:
Including nested templates:
index.js:
main.ejs:
hyperlink.ejs:
As a result, renderedHtml becomes a string <h1><a href="http://example.com">Example</a></h1>.