2013-09-21 83 views
4

我有一个路由器映射是这样的:组织烬模板文件夹

this.resource('eng', function(){ 
    this.route('home'); 
    this.resource('eng.rent', {path: 'rent' }, function(){ 
     this.route('boulderSmall', {path: 'boulder-small'}); 
     this.route('boulderXl', {path: 'boulder-xl'}); 
    });  
}); 

文件存储在“模板/工程”文件夹中的模板;对于“home”和“eng.rent”路由,一切正常:Ember可以自己找到模板文件所在的位置;但对于其他路线我必须指定的模板,如:

Importclimbing.EngRentBoulderSmallRoute = Importclimbing.StdEngRoute.extend({ 
    renderTemplate: function() { 
     this.render('eng/boulderSmall'); 
    } 
}); 

有人能解释灰烬如何查找模板文件?例如,如果我没有像上面那样为EngRentBoulderSmallRoute指定“renderTemplate”,那么该模板将不会呈现(即使我将“boulderSmall.hbs”文件放入“template”文件夹而不是“template/eng”;因此,如果我想将“boulderSmall.hbs”存储到“templates/eng/rent”文件夹中,应该将哪个路径传递给renderTemplate函数?

回答

3

最后我摆脱了这一点; kiwiupower的回答是正确的,因为Ember按照指示在文件夹和子文件夹中查找模板文件; 这个问题是由于yeoman,我用于开发;在grunt文件中,默认设置仅通过一级文件夹查找Ember模板;

使自耕农能够在模板文件夹结构也再深入,我做了这个变化:

1到手表任务livereload:

emberTemplates: { 
      files: '<%= yeoman.app %>/templates/**/**/*.hbs', 
      tasks: ['emberTemplates', 'livereload'] 
     }, 

我添加了一个“**/“为了让任务手表也模板目录

2灰烬模板任务的子文件夹的第二个层次:

emberTemplates: { 
     options: { 
      templateName: function (sourceFile) { 
       var templatePath = yeomanConfig.app + '/templates/'; 
       return sourceFile.replace(templatePath, ''); 
      } 
     }, 
     dist: { 
      files: { 
       '.tmp/scripts/compiled-templates.js': '<%= yeoman.app %>/templates/{,*/}{,*/}*.hbs' 
      } 
     } 
    } 

我在dist.files对象中添加了一个“{,/}”; 如果你需要yeoman来监视/编译第三级子文件夹或更多,你需要修改这两项任务,增加更多的“ * /”和“{,* /}”

5

您的文件夹结构应该看起来像这一点。

首先,你需要重命名eng.rent路线rent所以路由器看起来像这样

this.resource('eng', function(){ 
    this.route('home'); 
    this.resource('rent', {path: 'rent' }, function(){ 
     this.route('boulderSmall', {path: 'boulder-small'}); 
     this.route('boulderXl', {path: 'boulder-xl'}); 
    });  
}); 

然后你的模板和文件夹应该以这种方式命名。

templates   ## this is a folder 
    |--eng   ## this is a folder 
     |--home.hbs 
    |--rent  ## this is a folder 
     |--boulder_small.hbs 
     |--boulder_xl.hbs 
    application.hbs 
    eng.hbs 
    rent.hbs 

我希望这会有所帮助。 干杯

+0

不幸的是它不工作;如果我将“reng.hbs”重命名为“eng.rent.hbs”并将其放入“模板”文件夹中,则它不会呈现(可以将它保存到templates/eng文件夹中并简单地命名为“rent.hbs”) ;如果我把hbs文件放到eng.rent子文件夹中,它们不会呈现... –

+0

我刚更新了应该为你工作的答案。干杯 – kiwiupover

+0

不,还不行;这是我所做的第一次尝试之一(除了我已经在camelcase中命名了所有.hbs文件,例如boulderSmall.hbs);我使用yeoman部署应用程序的应用程序,我不知道这是否会改变一些东西... –