Search code examples
ember.jsember-cli

How do you set variable in route and display in template?


I am looking to set a variable for each page that is set to text to display as a dynamic header sort of thing. How would I set a variable in a route and display it in the corresponding template? So far everything I have tried is not working.


Solution

  • The context of a template in a route is its controller, not its route. Try moving the action to the controller.

    See updated twiddle: https://ember-twiddle.com/b454e10355ae8c708c3b8dc24b51e44e?openFiles=controllers.my-route.js%2C

    For more information about controllers: https://guides.emberjs.com/v2.16.0/controllers/