Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created September 4, 2012 00:44
Show Gist options
  • Save ishiduca/3615350 to your computer and use it in GitHub Desktop.
Save ishiduca/3615350 to your computer and use it in GitHub Desktop.
EJS apply 'include'
'use strict';
var ejs = require('ejs');
var usersEjs = './views/users.ejs';
var users = require('fs').readFileSync( usersEjs, 'utf-8' );
console.log( ejs.render( users, {
filename: usersEjs // required
, title : 'TITLE'
, users : [ 'hoge', 'huga', 'foo' ]
})
);
// <!doctype html>
// <head>
// <meta charset="utf-8" />
// <title>TITLE</title>
// </head>
// <body>
// <ul>
// <li>hoge</li>
// <li>huga</li>
// <li>foos</li>
// </ul>
// </body>
// look at https://github.com/visionmedia/ejs
<li><%= user %></li>
<!doctype html>
<head>
<meta charset="utf-8" />
<title><%= title %></title>
</head>
<body>
<ul>
<% users.forEach(function (user) { -%>
<% include user/show -%>
<% }); -%>
</ul>
</body>
@ishiduca
Copy link
Author

ishiduca commented Sep 4, 2012

render.js
views/
    users.ejs
    user/
        show.ejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment