I have the following in my handlebars tag:
{{#editmode mode}}
<div class="form-group login-input">
<i class="fa fa-key overlay"></i>
<input type="password" class="form-control text-input" name="password" placeholder="Password" value="{{password}}">
</div>
<div class="form-group login-input">
<i class="fa fa-key overlay"></i>
<input type="password" class="form-control text-input" name="password_confirmation" value="{{password}}">
</div>
{{/editmode}}
and I have the following registered as my helper function:
Handlebars.registerHelper('editmode', function(mode){
return mode == 'edit' ? true : false;
});
The object passed to the handlebars template looks something like this:
{
firstname: 'Test',
lastname: 'Test lastname',
mode: 'new
}
So basically, whenever the 'mode' variable is 'new', I want to show the password fields, otherwise hide them, but right now they are always hidden. Any ideas?
I have the following in my handlebars tag:
{{#editmode mode}}
<div class="form-group login-input">
<i class="fa fa-key overlay"></i>
<input type="password" class="form-control text-input" name="password" placeholder="Password" value="{{password}}">
</div>
<div class="form-group login-input">
<i class="fa fa-key overlay"></i>
<input type="password" class="form-control text-input" name="password_confirmation" value="{{password}}">
</div>
{{/editmode}}
and I have the following registered as my helper function:
Handlebars.registerHelper('editmode', function(mode){
return mode == 'edit' ? true : false;
});
The object passed to the handlebars template looks something like this:
{
firstname: 'Test',
lastname: 'Test lastname',
mode: 'new
}
So basically, whenever the 'mode' variable is 'new', I want to show the password fields, otherwise hide them, but right now they are always hidden. Any ideas?
Share Improve this question asked May 20, 2015 at 14:43 BraviBravi 7733 gold badges8 silver badges30 bronze badges2 Answers
Reset to default 3I figured it out. This did the trick:
Handlebars.registerHelper('editmode', function(mode, options){
return mode == 'edit' ? '' : options.fn();
});
You can use if
statement.
<div class="form-group login-input">
<i class="fa fa-key overlay"></i>
<input type="password" class="form-control text-input" name="password" placeholder="Password" value="{{password}}">
</div>
{{#if mode}}
<div class="form-group login-input">
<i class="fa fa-key overlay"></i>
<input type="password" class="form-control text-input" name="password_confirmation" value="{{password}}">
</div>
{{/if}}