Ember Js ·

Passing a value to ember.js view from handlebars template

This is one of those things that should be easy and it’s probably obvious to most people but it threw me for a while.
I wanted to pass a value into my ember.js view at the moment that I declare the view. It’s a static value, just a css class
name, so it doesn’t need to be bound to anything. Turns out it’s really not that hard:

Add a property to your view:


App.ModalView = Ember.View.extend({
  aClassName: 'modal'
});
</pre>

<p>When you use the view just set the property:</p>

{{#view App.ModalView aClassName="wide_modal"}}
  Some great content goes here
{{/view}}
</pre>

<p>Use the value in your template:</p>

  <div {{bindAttr class="view.aClassName"}}>
    More stuff here
  </div>
</pre>