Juan Jardim
Juan Jardim

Reputation: 2252

Evaluate two conditions in handlebar using ember

I was wondering if its possible to do something like this:

{{#if ClientController.Client.number && PhoneController.hasLinesToInstall}}
...
{{/if}}}

Thanks,

Juanitos

Upvotes: 7

Views: 16094

Answers (4)

Kronan
Kronan

Reputation: 181

If you are using ember-template-helpers You can use evaluate in your template directly with:

{{#if (and ClientController.Client.number PhoneController.hasLinesToInstall)}}
...
{{/if}}}

Upvotes: 1

spirito_libero
spirito_libero

Reputation: 1332

For me, this worked:

Ember.computed.and('firstComputedProperty', 'secondComputedProperty')

Upvotes: 1

Max Wallace
Max Wallace

Reputation: 3768

It's not supported out-of-the-box, but you can use the addon https://github.com/jmurphyau/ember-truth-helpers:

ember install ember-truth-helpers

Then, in your template:

{{#if (and ClientController.Client.number PhoneController.hasLinesToInstall)}}
  ...
{{/if}}}

Previously, the community's understanding was that templates should be largely free of logic. Overtime, our viewpoint has shifted towards putting more declarative logic in templates-- along with ember-truth-helpers, ember-composable-helpers is a great example of this.

Upvotes: 6

Anonymous
Anonymous

Reputation: 6251

I don't think it's possible to chain conditions like that in handlebars like that - I can't find anything about it in the documentation.

You could nest them though, like this:

{{#if ClientController.Client.number}}
    {{#if PhoneController.hasLinesToInstall}}
        ...
    {{/if}}
{{/if}}

That would achieve the same outcome.

Upvotes: 10

Related Questions