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

前端 未结 13 1986
一向
一向 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:41

    The same way you would do it with anything in js, typeof foo == 'undefined', or since "locals" is the name of the object containing them, you can do if (locals.foo). It's just raw js :p

提交回复
热议问题