David Jones

Ejs template and undefined variables

So today I was running into an issue while using Node.js and the EJS templates. The issue was that if I was echoing a variable that didnt exist 'undefined' would be echoed rather than nothing. The way around this is the following:

<%= variable || '' %>

This will echo out the variable if it exists otherwise it will be blank.