Include a filter that checks if a value if falsy and, in that case, replaces it with a default one (passed as an optional argument, empty string by default).
This is useful to make your intention clear (instead of <%= value || "my value" %>) and to combine it with other filters (e.g. <%=: value | default | capitalize %>).
It includes some tests.
Add default filter
Include a filter sets a default `def` value if `obj` is falsy.
If no default value is passed, it uses an empty string.
Includes unit tests
hmm this would maybe make more sense if it were a null == val check, but otherwise I think || is more clear, to me "default" would mean 0 and false would be allowed
null == val
You are right, it is not so clear and it does not add much value. Thanks for your comment.
an progress on this ?
If the given variable is undefined, then give a default value. This is quite useful.
@yeasy this won't be added to ejs. You can use <%= yourvariable || defaultvalue %> instead.
<%= yourvariable || defaultvalue %>
We can close this.
Just a note, this version of EJS is no longer supported. V2, which is the one on NPM, is here: https://github.com/mde/ejs
<%= yourvariable || defaultvalue %> seems not work.
I rend the ejs without giving the yourvariable value.
The error is yourvariable is not defined.