Defining a View Edit Page


You can use Ember.View to render a Handlebars template and insert it into the DOM.

To tell the view which template to use, set its templateName property. For example, if I had a <script> tag like this:

1
2
3
4
5
6
7
<html>
  <head>
    <script type="text/x-handlebars" data-template-name="say-hello">
      Hello, <b>{{view.name}}</b>
    </script>
  </head>
</html>

I would set the templateName property to "say-hello".

1
2
3
4
var view = Ember.View.create({
  templateName: 'say-hello',
  name: "Bob"
});

Note: For the remainder of the guide, the templateName property will be omitted from most examples. You can assume that if we show a code sample that includes an Ember.View and a Handlebars template, the view has been configured to display that template via the templateName property.

You can append views to the document by calling appendTo:

1
view.appendTo('#container');

As a shorthand, you can append a view to the document body by calling append:

1
view.append();

To remove a view from the document, call remove:

1
view.remove();