Below is the code from EJS file which i am rendering but i am not able figure out the correct syntax for the if statement shorthand.
Here "cchoice" is the object that i am passing while rendering and it is working if i remove the if statement, hence there is no problem in getting its value.
<h1>Welcome,
<%= cchoice %>
</h1>
<% cchoice =='dog' ? <p>good choice</p> : <p>cool!</p> %>
The error i am getting is :
SyntaxError: Unexpected token < in /views/new.ejs while compiling ejs
Suggest the correct syntax for the above shorthand for if statement.
You need to use <%- and surround the HTML with quote:
<%- cchoice =='dog' ? '<p>good choice<p>' : '<p>cool!</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