panchita911 panchita911 -4 years ago 374
Node.js Question

How to convert handlebars to ejs

This is probably an easy question but I can't figure it out.

I want to change this handlebar code into ejs

{{#if hasErrors}}
<div class="alert alert-danger">
{{#each messages}}
<p>{{ this }}</p>

I tried but i'm getting syntax error

<%= if (Errors) {%>
<div class="alert alert-danger">
<%= each messages %>
<p><%= this%></p>
<% }%>

Answer Source

If your "hasError" variable is of type boolean, and your messages variable is an array of message strings;

<% if (hasErrors) {%>
 <div class="alert alert-danger">
     <% messages.forEach(function(message){ %>
       <p><%= message %></p>
     <% });%>
<% }%>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download