Created
January 19, 2017 14:37
-
-
Save git-toni/b9ed2d43d80e9e6657234a94d002ea6c to your computer and use it in GitHub Desktop.
EJS templates + partials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span>IM ONE</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Hellp</p> | |
<%- include(el.filename); %> | |
<p>Bye</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span>IM TWO</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment