ejs remote client side includes.
html = ejs.rr('sayhello.ejs', {name: 'Simon'});
- Install with
npm i ejs-render-remote
- Include this script
<script src="node_modules/ejs-render-remote/ejs-render-remote.js"></script>
- Create a file with your template, for example
templates/hello-world.ejs
containinghello <%= name %>!
- Render the remote template:
someDomelement.outerHTML = ejs.rr('templates/hello-world.ejs', {name: 'Simon'});
See examples
folder.
ejs.rr
(render remote) renders the remote template. It makes an ajax call to fetch the template and then ejs.render
s it.
The resulting ejs template function is cached, so the second time this function is invoked for that same template, ejs.rr
returns the rendered template synchronously.
Since ejs.rr
is async, you can call ejs.preloadTemplate
before invoking ejs.rr
to warm the template cache up for that templateUrl
.
By doing so the call to ejs.rr
will return the rendered template string right away.