Skip to content

Instantly share code, notes, and snippets.

@git-toni
Created January 19, 2017 14:37
Show Gist options
  • Save git-toni/b9ed2d43d80e9e6657234a94d002ea6c to your computer and use it in GitHub Desktop.
Save git-toni/b9ed2d43d80e9e6657234a94d002ea6c to your computer and use it in GitHub Desktop.
EJS templates + partials
try {
var ejs = require('ejs');
var fs = require('fs');
var data = [
{filename:'one', data:{ number:2,str:'tool' }},
{filename:'two', data:{}},
{filename:'three', data:{}},
]
var tfname = __dirname + '/template.ejs'
var template = fs.readFileSync(tfname, 'utf-8');
for(var el of data){
var html = ejs.render( template , {filename:tfname, el: el} );
fs.writeFileSync("./"+el.filename+".html", html, 'utf8');
}
}catch (e){
console.log(e)
}
<span>IM ONE</span>
<p>Hellp</p>
<%- include(el.filename); %>
<p>Bye</p>
<span>IM TWO</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment