Created
October 9, 2010 18:21
-
-
Save remy/618458 to your computer and use it in GitHub Desktop.
Using ejs (node flavour), how to default a value if missing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- prints "no email given" if no email passed in to locals, otherwise shows val --> | |
| <%=: locals | get:"email","no email given" %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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