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>Wele,
<%= 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 piling ejs
Suggest the correct syntax for the above shorthand for if statement.
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>Wele,
<%= 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 piling ejs
Suggest the correct syntax for the above shorthand for if statement.
Share Improve this question asked Aug 23, 2018 at 6:56 Gavish KumarGavish Kumar 591 silver badge9 bronze badges1 Answer
Reset to default 8You need to use <%-
and surround the HTML with quote:
<%- cchoice =='dog' ? '<p>good choice<p>' : '<p>cool!</p>' %>