javascript - How would you check for undefined property in ejs for node.js? -
What is the best way to check an undefined property in the EJS template?
(I '
Example:
var tpl =' & lt;% if (foo) {%> defined Foo & lt ;%} Other {%> Foo undefined & lt;%}% & gt; '; Console.log (ejs.render (tpl, {local: {time: "falcon"}}))); I hope it has to render "foo undefined" instead it throws an foo undefined error. I know that this is not an issue because it is expected behavior.
var tpl = '& lt;
% (hypoproperty ("foo")) {%> defined foo & lt;%} other {%> Foo undefined & lt;%}% & gt; '; Console.log (ejs.render (tpl, {local: {time: "falcon"}})));
It does not make any errors.
Is there a better way to keep the template clean? Or why this error is thrown? "post-text" itemprop = "text">
Another way to test for an asset is indirectly referred to as local objects for example : var tpl = '& lt;% if (localals.foo) {%> Foo defined & lt;%} other {%> Foo undefined & lt;%}% & gt; ; Console.log (ejs.render (tpl, {local: {time: "falcon"}})));
Comments
Post a Comment