Is it possible to load handlebar template with scr

2019-03-09 02:20发布

Simply enough I do not want to define all my handlebar templates in my html file

I tried this

<script type="text/x-handlebars" data-template-name="nav-bar" src="template.handlebar"></script>

But this did not work. Can I not define templates my template programmatically or even just load handlebar files so that I can reuse and also I feel it makes things a bit more maintainable.

I tried just loading them with ajax and appending them to the head, this works fine I can see it there but ember.js doesn't read it after ember has already been loaded and the templates are not defined.

8条回答
萌系小妹纸
2楼-- · 2019-03-09 03:11

It is possible, but you will need to precompile your templates first. This will also allow you to include all your templates within one file.

Later on, you will need to include the javascript file.

<script src="path/to/compiled/templates.js" type="text/javascript"></script>
查看更多
老娘就宠你
3楼-- · 2019-03-09 03:14

If you load your templates into the DOM before loading Ember, then you don't need to compile or register your templates. Ember will come along after and do it for you.

Here is an article showing how:

http://weboriented.wordpress.com/2012/09/02/loading-handlebars-templates-in-ember-using-curl-js/

查看更多
登录 后发表回答