1

Is it possible to separate the templates .hbs from component class javascript .js in Ember 3.15 Octane.

A folder structure like:

app/
   components/
     js/
     hbs/
  • It is possible. But not recommended. Why do you want this? You can just place your templates to `app/templates/component/component-name.js` and keep your `.js` where it is – Lux Jan 23 '20 at 16:07
  • Thanks @Lux for your comment. I was not sure that the classic structure works in 3.15. I can adapt that to my project. – Jamiu Adeleke Jan 23 '20 at 17:14
  • `3.15` is *just* a minor release. Everything that worked in `3.0` should continue to work. – Lux Jan 23 '20 at 17:38

1 Answers1

2

The “classic” directory structure does separate component Javascript and template files, but not in the way you specified. Running ember generate component component-name --component-structure classic --gc would result in this structure (ignoring the tests directory):

app/
  components/
    component-name.js
    templates/
      component-name.hbs

If you really must have the directory structure you specified, you could accomplish it using a custom resolver. Here’s a blog post that gives a high-level overview of that. I’d caution against that kind of thing, though, as it’s usually beneficial to stick with what most of the community uses, and in 3.15 that’s the flat component structure. What’s your use case?

Buck Doyle
  • 6,333
  • 1
  • 22
  • 35
  • 1
    Thank you, for your response. I did not know I could use the classic directory structure. This should solve it for me as it separates the js files from the hbs files. I just wasn't sure that the classic structure is supported in Octane. Thank you. – Jamiu Adeleke Jan 23 '20 at 16:58