Last active
October 24, 2017 14:40
-
-
Save Sysetup/f62e8621198a6f8f307df5480060fd6a to your computer and use it in GitHub Desktop.
EJS Template
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
<div class="list-group"> | |
<!-- loop over blog posts and render them --> | |
<% posts.forEach((post) => { %> | |
<a href="/post/<%= post.id %>" class="list-group-item"> | |
<h4 class="list-group-item-heading"><%= post.title %></h4> | |
<p class="list-group-item-text"><%= post.author %></p> | |
</a> | |
<% }) %> | |
</div> | |
/////////// | |
<%if (recipes.length > 0) { %> | |
// Do something with more than 1 recipe | |
<% } %> | |
/////////// | |
<h2>Loop</h2> | |
<ul> | |
<% drinks.forEach(function(drink) { %> | |
<li><%= drink.name %> - <%= drink.drunkness %></li> | |
<% include user/show %> | |
<% }); %> | |
</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
// index page | |
app.get('/', function(req, res) { | |
var drinks = [ | |
{ name: 'Bloody Mary', drunkness: 3 }, | |
{ name: 'Martini', drunkness: 5 }, | |
{ name: 'Scotch', drunkness: 10 } | |
]; | |
var tagline = "Any code of your own that you haven't looked at for six or more months might as well have been written by someone else."; | |
res.render('pages/index', { | |
drinks: drinks, | |
tagline: tagline | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment