Reputation: 531
I am using Handlebars to display my content, How will this following code in ejs be displayed in handlebars to display data. I currently new to Nodejs , can someone suggest possible solution
And which is better to use ,ejs or handlebars
<% if(files){ %>
<% files.forEach(function(file) { %>
<div class="card card-body mb-3">
<% if(file.isImage) { %>
<img src="image/<%= file.filename %>" alt="">
<% } else { %>
<%= file.filename %>
<% } %>
<form method="POST" action="/files/<%= file._id %>?_method=DELETE">
<button class="btn btn-danger btn-block mt-4">Delete</button>
</form>
</div>
<% }) %>
<% } else { %>
<p>No files to show</p>
<% } %>
Upvotes: 0
Views: 205
Reputation: 1255
{{#each files}}
<div class="card card-body mb-3">
{{#if this.isImage}}
<img src="image/{{this.filename}}" alt="">
{{else}}
{{this.filename}}
{{/if}}
<form method="POST" action="/files/{{this._id}}?_method=DELETE">
<button class="btn btn-danger btn-block mt-4">Delete</button>
</form>
</div>
{{else}}
<p>No files to show</p>
{{/each}}
here you can find the comparaison between different javascript templating engines.
Upvotes: 1