- Load EJS template files asynchronously in browser.
include
support in browser, and it loads included templates recursively.
Example code is located in /example
directory.
<script src="ejs-2.4.2.min.js" type="text/javascript"></script>
<script src="ejs-browser-async.min.js" type="text/javascript"></script>
- path: relative to the page, or absolute path of the ejs template file
- data: parameters that you want to pass to the templates
- callback: callback function that gives you rendered string. callback has two arguments,
error
andrendered
.- error: Error object if error occurs, otherwise null.
- rendered: Rendered string result.
ejs.renderAsync(
'./templates/index.ejs',
{
sitename: 'EJS Async',
copyright: 'Devrama.com'
},
function(err, rendered){
if(!err){
var el = document.getElementById('ejs-render');
el.innerHTML = rendered;
}
else {
throw new Error('EJS template error!');
}
}
);
MIT