I have implemented a custom helper in Handlebars to create an if == "some string"
type of helper. Here is the code for the helper:
Handlebars.registerHelper('if_eq', function(a, b, opts) {
if(a == b) // Or === depending on your needs
return opts.fn(this);
else
return opts.inverse(this);
});
This is the template structure:
<div id="appStoreParametersModal" class="modal-dialog">
<div class="modal-content appStoreParametersModal">
<div class="modal-header hypersignModalHeader">
<h3>{{appName}}</h3>
</div>
<div class="modal-body">
<div id="app-params">
{{#each appParm}}
<form>
{{#if_eq uiControlType "text"}}
<div class="form-group">
<label for="{{qsName}}">{{uiName}}</label>
<input type="text" class="form-control" id="{{qsName}}" placeholder="{{uiName}}"/>
</div>
{{else if_eq uiControlType "dropdown"}}
<div class="form-group">
<label for="{{qsName}}">{{uiName}}</label>
<select class="form-control" id="{{qsName}}">
{{#each defaultVals}}
<option value="{{value}}">{{displayName}}</option>
{{/each}}
</select>
</div>
{{/if_eq}}
</form>
{{/each}}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning cancel" data-dismiss="modal" id="cancel">Cancel</button>
<button type="button" class="btn btn-success" id="appStoreNext">Next</button>
</div>
</div>
</div>
I encountered the following error:
Uncaught Error: if_eq doesn't match each
It seems like there is an issue with using the {{else}}
statement, as when I only use the if_eq
helper without an else
, it works fine. I am relatively new to Handlebars, so I might be overlooking something simple.