Reputation: 2466
I've added a custom helper in Handlebars to accomplish an if == "some string"
type helper. The helper code is this:
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);
});
The template is this:
<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'm getting this error:
Uncaught Error: if_eq doesn't match each
It seems to be a problem with using the {{else}}
, because if I only use the if_eq
helper without an else
, then it works fine. I'm pretty new to Handlebars, so I'm sure I'm missing something stupid.
Upvotes: 2
Views: 3561
Reputation: 1967
if_eq doesn't match if
is thrown when you have {{#if_eq stuff "stuff"}}
but you end it by mistake in {{/if}}
instead of {{/if_eq}}
.
Upvotes: 14