What is the proper way to check for existence of variable in an EJS template (using ExpressJS)?

前端 未结 13 1934
一向
一向 2020-12-12 16:02

On the EJS github page, there is one and only one simple example: https://github.com/visionmedia/ejs

Example

<% if (user) { %>
    

&

相关标签:
13条回答
  • 2020-12-12 16:46

    For your if statement you need to use typeof:

    <% if (typeof user == 'object' && user) { %>
    
    <% } %>
    
    0 讨论(0)
提交回复
热议问题