Skip to content

Instantly share code, notes, and snippets.

@Sysetup
Last active October 24, 2017 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sysetup/f62e8621198a6f8f307df5480060fd6a to your computer and use it in GitHub Desktop.
Save Sysetup/f62e8621198a6f8f307df5480060fd6a to your computer and use it in GitHub Desktop.
EJS Template
<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>
// 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