jeudi 26 novembre 2015

How to add templates to sub-directories in Ember?

I am quite sure the answer to my question is somewhere in some docs, I read many pages, on official and unofficial websites, many related questions on SO, but my google-fu seems not developed enough to help me find the answer, so here I am.

In my team we are using Ember-cli for some web application. We have the classic app/templates folder in which we put the .hbs of each "controller" we have. In those handlebars templates, we use components which are in app/templates/components.

We recently have reached a point where the app/templates/components is too big. I thought that it would be good idea to split them into sub-directories, e.g.

  • app/templates/product1 containing specific-to-product1 components + the base product1 handlebar (the one called in app/router.js, a "controler's hbs").
  • app/templates/product2 containing specific-to-product2 components + the base product2 handlebar (the one called in app/router.js, a "controler's hbs").

But when I do that, it doesn't work and displays a white page:

  • If I move the "controler's hbs" from app/templates to app/templates/product1, I have a whole white page with nothing loaded.
  • If I move a component from app/templates/components to app/templates/product1, the "controler's hbs" shows, but I have an empty block where my component is supposed to be.

I don't know if I have to configure ember for it to recursively search for handlebars in the app/templates folder, and/or if I have to change the router.js, and how to call my components so ember knows where they are.

Thanks in advance,

Benjamin




Aucun commentaire:

Enregistrer un commentaire