I have a page that makes a foreach and show some photos like this
<% imgs.forEach(function(img) { %>
<img src="uploads/<%=user.username%>/screenshots/<%= img %>">
<% }); %>
And I want make a if statement because, in case that not photos to show gives a message like this:
"no photos uploaded"
Something like this:
<% if(imgs.length > 0){ %>
<% imgs.forEach(function(img) { %>
<img src="uploads/<%=user.username%>/screenshots/<%= img %>">
<% }); %>
<% } else{ %>
<p>no photos uploaded</p>
<% } %>
Reference
The shorthand version is correct, but it does have a syntax error
<%= role === 'admin' ? 'Super Admin' : 'Admin' %>
Or
<% if(role === 'admin'){ %>
<p>Super Admin</p>
<% } else{ %>
<p>Admin</p>
<% } %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With