Reputation: 4430
On the client, I would like to be able to do something similar to the below :
public_html/index.html
<html>
<head>
<script src="ejs-or-similar.js"></script>
</head>
<body>
<div id="some-partial"></div>
<script>
var partialHTML = Magic.render('partials/some-partial.ejs');
document.getElementById('some-partial').innerHTML = partialHTML;
</script>
</body>
</html>
public_html/partials/some-partial.ejs
<div>Hi, I come from a different file!</div>
Is it possible ?
If yes, which EJS file/documentation should I use :
http://ejs.co/
http://www.embeddedjs.com/
https://github.com/tj/ejs
Please note that I'm not interested in a discussion as to whether client-side templating is a good or bad idea, etc... Just saving everyone some precious time in advance :-)
Upvotes: 4
Views: 1384
Reputation: 2364
EJS will allow you to render out templates on the client side, but you will need to provide it the template string directly and not just the file path as it does not support XHR.
ejs.co (github.com/mde/ejs) is version 2 of EJS and is more actively supported.
Upvotes: 1