How check variable for empty-Collection of common programming errors
Are you using an out-of-date version of JsRender? The syntax is {{:name}}
, and it automatically renders an empty string is name is undefined or null. Unit test here: https://github.com/BorisMoore/jsrender/blob/master/test/unit-tests/tests-jsrender-no-jquery.js#L108
With the latest version you can even write {{:a.b.c.name noerror=true}}
and it will render the empty string even if any of name
, or a.b.c
or a.b
or a
are undefined or null.
You don’t need to wrap in an {{if ...}}...{{/if}}