0
votes

What is the context of an if-statement in a template or a component?

{{#if showBackButton}}
   <div>....</div>
{{/if}}

How/where to define the showBackButton? I tried it in the application controller but it didn't find it.

Details

I have a header component called eea-header.hbs. It is inluded in the application.hbs to be shown on top of the page for all pages (routes) the application may have. But I have some conditional statement in the header to turn off/on different parts of the header. Ideally I want to define properties like showBackButton in each route, because teh route knows when each property shall be true/false.

Shall I put this in the route or the controller? Syntax? I have tried:

showBackButton: true,

and

showBackButton: Ember.computed(function() {
    return true;
}),

and

showBackButton() {
    return true;
}),

without luck. If the answer is the controller, can all templates access such properties in the application controller or do I have to define them in each controller.

I want to be ember 2.0 compatible.

Apologies for this basic question, but I have read the ember documentation and it doesn't address this basic question.

2

2 Answers

1
votes

If you define property in correct Controller:

showBackButton: true

Then you are able to access it in Route template:

{{showBackButton}} // true

Demo here. Code here.

1
votes

If the if-statement is in your component template,then showBackButton will have to be property of the component. The component cannot find this property from application route or controller.

In your case, you need this property to be changed by serveral other routes, So you can have this property in application and then pass the property to the component. From the other routes, you can get application controller and modify the property. (or) You can simply inject the property to all routes and components.

To define a property in a controller, showBackButton: true.