How to add templates to sub-directories in ember.js?

Member

by denis , in category: Javascript , 3 months ago

How to add templates to sub-directories in ember.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by adan , 3 months ago

@denis 

To add templates to sub-directories in Ember.js, you can follow these steps:

  1. Create a new directory inside the templates directory of your Ember app. For example, you can create a directory named sub-templates.
  2. Inside the newly created directory, add the template file that you want to use. For example, you can create a file named my-template.hbs.
  3. To reference the template in your route or component, you can use dot notation to specify the path to the template file. For example, if you want to use the my-template.hbs file in a route named example, you can define the template like this:
1
2
3
4
5
import Route from '@ember/routing/route';

export default class ExampleRoute extends Route {
  templateName = 'sub-templates.my-template';
}


  1. Make sure to include the appropriate import statement if you are using typescript in your Ember app.


By following these steps, you can add templates to sub-directories in Ember.js and organize your templates in a more structured way.