-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<ul> | ||
<% | ||
users.forEach(function (user) { | ||
echo('<li>'); | ||
echo('<strong>' + user.name + '</strong>'); | ||
echo('is a ' + user.age + ' year old ' + user.species); | ||
echo('</li>\n'); | ||
}); | ||
-%> | ||
</ul> | ||
|
||
<ul> | ||
<% | ||
users.forEach(function (user) { | ||
echo(include('./partial.ejs', {user: user})); | ||
}); | ||
%> | ||
</ul> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Believe it or not, you can declare and use functions in EJS templates too. | ||
*/ | ||
|
||
var ejs = require('../'); | ||
var read = require('fs').readFileSync; | ||
var join = require('path').join; | ||
var path = join(__dirname, '/output-function.ejs'); | ||
var data = { | ||
users: [ | ||
{ name: 'Tobi', age: 2, species: 'ferret' }, | ||
{ name: 'Loki', age: 2, species: 'ferret' }, | ||
{ name: 'Jane', age: 6, species: 'ferret' } | ||
] | ||
}; | ||
|
||
var ret = ejs.compile(read(path, 'utf8'), { | ||
filename: path, | ||
outputFunctionName: 'echo' | ||
})(data); | ||
|
||
console.log(ret); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<li> | ||
<strong><%= user.name %></strong> | ||
is a <%= user.age %> year old <%= user.species %> | ||
</li> |
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