{"id":6914,"date":"2014-05-11T17:43:52","date_gmt":"2014-05-11T17:43:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/11\/jsrender-optional-model-properties-collection-of-common-programming-errors\/"},"modified":"2014-05-11T17:43:52","modified_gmt":"2014-05-11T17:43:52","slug":"jsrender-optional-model-properties-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/11\/jsrender-optional-model-properties-collection-of-common-programming-errors\/","title":{"rendered":"jsRender optional model properties-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;d like to have my jsRender templates optionally include an &#8220;options&#8221; property to provide optional fall-backs if a property is not included; specifically rendering one element if the &#8220;options&#8221; property is included, or another if it is not. Everything works fine if the model passed in contains the property in question, but even <code>{{if typeof ~options.someOption !== 'undefined'}}<\/code> gives me <code>Error: Cannot read property 'someOption' of undefined.<\/code><\/p>\n<p>Has anyone dealt with this? If so, how do you handle properties of the model passed in that do no exist?<\/p>\n<p><strong>EDIT:<\/strong> This question is really about how to handle missing properties of a model. Given a model with properties A and B, if property B is missing from the model but it is referenced in the template, how can I prevent error messages and handle it&#8217;s absence elegantly?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;d like to have my jsRender templates optionally include an &#8220;options&#8221; property to provide optional fall-backs if a property is not included; specifically rendering one element if the &#8220;options&#8221; property is included, or another if it is not. Everything works fine if the model passed in contains the property in question, but even {{if typeof [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6914","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6914"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6914\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}