Define application template in Ember.View in the most recent Ember.js Build

微笑、不失礼 提交于 2019-12-30 10:05:14

问题


I recently upgraded to the most recent Ember.js build (built from the GitHub page.)

When using the new router, does this no longer work?

App.ApplicationView = Ember.View.extend({
    template: Ember.Handlebars.compile("Hello")
});

I much prefer to define my templates in my js file rather than index.html. I believe it is much cleaner. However, the above does not render!

Any suggestions? Thanks!


回答1:


For Ember 1.0, templates should be defined in index.html or in separate files that are provided to your application via a build tool.

Some examples:

  • For Grunt
  • For Brunch
  • For the Rails Asset Pipeline
  • For Iridium
  • A Standalone Precompiler

If you really, really want to put your template in JavaScript, you can put this in your application template:

<script type="text/x-handlebars">
  {{view App.MyView}}
</script>

And then define your view:

App.MyView = Ember.View.extend({
  template: Ember.Handlebars.compile("Whatever you want here")
});

That said, the happy path in Ember is to use external templates for each of your routes, either in your HTML when you're getting started, or using a build step so you can keep them out of your index.html.



来源:https://stackoverflow.com/questions/14271651/define-application-template-in-ember-view-in-the-most-recent-ember-js-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!