Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organize ember templates in folders

Tags:

ember.js

I have a router map like this:

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'});
    });     
});

the template files are stored in "templates/eng" folder; for the "home" and "eng.rent" routes everything is ok: Ember can find by itself where the template files are; but for the other routes i have to specify where the template is, like:

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

Can someone explain how Ember looks for template files? For example, if i don't specify "renderTemplate" for EngRentBoulderSmallRoute as above, the template will not render (even if i put the "boulderSmall.hbs" file into "template" folder instead of "template/eng"; and so, where Ember look for this template by default? And if i would like to store "boulderSmall.hbs" into "templates/eng/rent" folder, which path should i pass to renderTemplate function?

like image 895
Cereal Killer Avatar asked Feb 15 '23 05:02

Cereal Killer


1 Answers

Your folder structure should look like this.

First you need to rename the eng.rent route rent so the router looks like this

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'});
    });     
});

Then your templates and folders should be named this way.

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

I hope this helps. Cheers

like image 62
kiwiupover Avatar answered Mar 11 '23 18:03

kiwiupover