Created
September 4, 2012 00:44
-
-
Save ishiduca/3615350 to your computer and use it in GitHub Desktop.
EJS apply 'include'
This file contains hidden or 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
'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 |
This file contains hidden or 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
<li><%= user %></li> |
This file contains hidden or 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
<!doctype html> | |
<head> | |
<meta charset="utf-8" /> | |
<title><%= title %></title> | |
</head> | |
<body> | |
<ul> | |
<% users.forEach(function (user) { -%> | |
<% include user/show -%> | |
<% }); -%> | |
</ul> | |
</body> |
Author
ishiduca
commented
Sep 4, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment