app.get('/', function (req, res) {
Photo.find({}, function (error, photos) {
var photoList = '';
photos.forEach(function (photo) {
photoList += '\
<a href="/sight-photo" style="background-image: url(' + photo.filePhoto + ')" class="photo_gallery-wrapper">\
<span class="photo_gallery-title">' + photo.titlePhoto + '</span>\
<span class="photo_gallery-desc-hover">\
</span>\
</a>\
';
});
res.render('index.ejs', {photoList: photoList});
});
});
<!-- begin snippet: js hide: false console: true babel: false -->
<% if (photoList.length) {
<% for(var i=0; i < photoList.length; i++) { %>
<a href="/sight-photo" style="background-image: url(<%=photo.filePhoto%>" class="photo_gallery-wrapper">
<span class="photo_gallery-title"><%=photo.titlePhoto%></span>
</a>
<% } %>
<% } %>