Noob - if condition doesn't work

Hej, i have the following problem:

i have a .hbs file with this code:

{{#if this.showRamCpuSettings}}
test
{{else}}
lol
{{/if}}

and in the route i have the following code:

import Route from '@ember/routing/route';
import {
  set
} from '@ember/object';

export default Route.extend({

  showRamCpuSettings: false,
  queryParams: {
    widget: ''
  },
  model(params) {

    if (params.widget == 'ramcpu') {
      set(this, "showRamCpuSettings", true);
      console.log("showRamCpuSettings: " + this.showRamCpuSettings); //output: showRamCpuSettings: true
    }

  },

  actions: {
    resetRoute() {
      const routeName = this.get('widgetsettings');

    }
  },
});

goal: if i get to the page i will parse a widgetName and i want to show different components at the end depends on the queryparams.

the console.log says to me that this.showRamCpuSettings is true. but the #if still shows me only “lol” (else). do someone know what i am doing wrong ?

Hey, I don’t know which version of Ember you use, but first thing is template doesn’t have access to routes properties, except model which is passed automatically.

So you can return object from model hook and access it in template as {{model. showRamCpuSettings}} Second thing is queryParams work differently than you have used it. Check guides Query Parameters - Routing - Ember Guides

1 Like