最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - If-else shorthand in ejs template? - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 8

You need to use <%- and surround the HTML with quote:

<%- cchoice =='dog' ? '<p>good choice<p>' : '<p>cool!</p>' %>
发布评论

评论列表(0)

  1. 暂无评论