dimanche 1 novembre 2015

How to check whether object is empty in handlebars if statement?

In handlebars i need to check if an object is empty and if it isn't then i need to run a loop to grab the content from the object. Below is my code and a link to codepen. I imagine this is quite simple but nothing seems to work. I would have thought that the handlebars #if statement would see an empty object as undefined or 0 and ultimately the condition would be unfulfilled.

<div class="temp"></div>

<script id="temp" type="x-handlebars-template">
    {{#if tabs}}
    <p>true</p>
    {{/if}}
</script>

var template = Handlebars.compile($("#temp").html());

var tabs = {};

var context = {
    tabs: tabs
}

$('.temp').html(template(context));

http://ift.tt/1MqMZnU

Aucun commentaire:

Enregistrer un commentaire