Handlebar Conditional Not Working
I have a handlebar template like this ... {{#cards}}
Solution 1:
Found a solution ....
I changed the helper function to
Handlebars.registerHelper("printButton", function() {
if (logged_in == 'Yes') { // logged_in is a dynamic variable whose value is set by user input.return"<button type='button' class='btn btn-primary check_od_session'>Add to my Planner</button>";
} else {
return"<button type='button' class='btn btn-primary check_od_session'>Login Register to add to your Planner</button>";
}
})
The key here is not to pass anything inside the function and I was able to do whatever comparisons/conditions I want to perform using any dynamic values/variables.
And in the template file, simply called the printButton function like this....
{{#cards}}
<divclass="modal fade"id="myModal"tabindex="-1"role="dialog"aria-labelledby="myModalLabel"><divclass="modal-dialog"role="document"><divclass="modal-content"><divclass="modal-header"><buttontype="button"class="close"data-dismiss="modal"aria-label="Close"><spanaria-hidden="true">×</span></button><h4class="modal-title"id="myModalLabel">{{ Session_type }}</h4></div><divclass="modal-body"><p>{{ Title }}</p><p>{{ Location }}</p></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-dismiss="modal">Close</button>
{{{ printButton }}}
</div></div></div></div>
{{/cards}}
I am sure there are better ways of doing this, but its working for my purposes.
Post a Comment for "Handlebar Conditional Not Working"