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}}
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">{{ Session_type }}</h4>
</div>
<div class="modal-body">
<p>{{ Title }}</p>
<p>{{ Location }}</p>
</div>
<div class="modal-footer">
<button type="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"