Is it possible to load handlebar template with script tag? Or define handlebar templates programmatically in Ember.js

后端 未结 8 521
臣服心动
臣服心动 2021-01-31 10:38

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

I tried this



        
8条回答
  •  面向向阳花
    2021-01-31 11:04

    Or define handlebar templates programatically in Ember.js

    You can define templates programmatically by using Ember.Handlebars.compile, see http://jsfiddle.net/pangratz666/wxrxT/:

    Ember.View.create({
        personName: 'Dr. Tobias Fünke',
        template: Ember.Handlebars.compile('Hello {{personName}}')
    }).append();​
    

    Or you add compiled templates to Ember.TEMPLATES array, see http://jsfiddle.net/pangratz666/58tFP/:

    Ember.TEMPLATES['myFunkyTemplate'] = Ember.Handlebars.compile('Hello {{personName}}');
    
    Ember.View.create({
        personName: 'Dr. Tobias Fünke',
        templateName: 'myFunkyTemplate'
    }).append();​
    

    I would recommend to use some tools like Richard Millan stated. Also take a look at interline/ember-skeleton which offers support for compilation of templates.

提交回复
热议问题