Render template from outside of templates folder


#1

How can I render a template that lives outside of the templates folder please?

At the moment I have a templates/cases/create-update.hbs and the following route.js import Ember from ‘ember’;

export default Ember.Route.extend({
    templateName: 'cases/create-update'
});

However if I move this template to /packaging/cases/create-update.hbs and change my route.js as follows I get a blank page. import Ember from ‘ember’;

export default Ember.Route.extend({
    templateName: '/packaging/cases/create-update'
});

It seems I can only specify templates inside of the template folder. Is that right? That seems a shame as I am using the PODs structure so that all of my related routes, controllers and templates live together and this seems to break that structure. I realise I can use the default template but I want two routes to share a template.


#2

Pod structure should work, however, what you have you listed isn’t quite pod structure. The path should be: /packaging/cases/create-update/template.hbs. With Pod structure, the file should be named template just as controllers are controller.js and routes are route.js.


#3

@sbatson5 Thanks for your advice. I will restate my question as I think it might be an XY Problem. How can I get the following routes to use the same template please? /packaging/cases/create/route.js /packaging/cases/update/route.js

Thanks Caltor


#4

The simplest option would be to have two different templates and just render the same component within both. That way you get the same functionality with both templates.


#5

@Caltor there’s no reason templateName wouldn’t work here.

in the update route.js, you can do this:

templateName: "packaging/cases/create"


#6

Interesting idea James. I’ll take a look at that.


#8

@alexspeller Ah yes that works fine, thanks. Three lessons from this for me.

  1. The template must be called template.hbs.
  2. Drop “/template.hbs” from the templateName property.
  3. The template needs to be at the same folder level as the route(s). I was putting the template up a level as it was being shared by two routes.

Caltor


#9

I went with @James-Byrne idea in the end. Using a component solved a few other problems I was having anyway. Thank you all for your input.