Skip to content

Instantly share code, notes, and snippets.

@remy
Created October 9, 2010 18:21
Show Gist options
  • Select an option

  • Save remy/618458 to your computer and use it in GitHub Desktop.

Select an option

Save remy/618458 to your computer and use it in GitHub Desktop.
Using ejs (node flavour), how to default a value if missing
<!-- prints "no email given" if no email passed in to locals, otherwise shows val -->
<%=: locals | get:"email","no email given" %>
// where ejs is the ejs required module
// overwrite the 'get' filter
ejs.filters.get = function(obj, prop, def) {
return obj[prop] === undefined ? def : obj[prop];
};
// for usage see example.ejs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment