Posts

Showing posts from May, 2013

JSON Object Property Hierarchy Bug in Handlebars

I recently ran into a bug with the Handlebars client-side templating system. This issue was that Handlebars wasn't picking up a property on the JSON object I passed into it -- or, more specifically, it wasn't picking up the value while within an "unless" conditional block. It was picking up the value outside of the block. The value in question was nested within another object of the object I passed in. After some digging, it turns out that, when within an "unless block", you need to add another ../ to the hierarchy. To illustrate the fix, here is an example of some code that won't work. In the following example, we are 2 levels deep within the object's properties, and want to use the Id property that resides at the root level. {{#unless IsDefault}} {{../../Id}} {{/unless}} To get the code to work, add an additional "../" as shown below. While this doesn't accurately represent the object's structure, it does fix th...