As I’m refactoring my code into components, I"m finding that component hierarchies are working well. The only issue I’m running into is with the template naming requirements. I’d like to be able to have multiple templates in a components directory, that I can lookup dynamically. An example below of whats working and whats not:
side-bar/
|__component.js
|__template.hbs
|__sidebar-links/
|_component.js
|_template.hbs
|_sidebar-drawer/
|_component.js
|_template-one.hbs
|_template-two.hbs
|_...
So – as a simplification, my sidebar-drawer component can make use of many templates (as partials, or sometimes childViews with the layout
property dynamically set), swapping them out based on links. I’d ideally like to group them together. Instead, to do something like this i"m forced to keep them in the /app/templates
directory, or treat them like components.
I think I can get this working by modifying the templates compiler (found [here]):
app._podTemplatePatterns = function() {
return this.registry.extensionsForType('template').map(function(extension) {
return new RegExp(extension + '$');
});
};
This compiles all templates having hbs
extensions, regardless of location. But I’m then unable to look them up – presumably i’d need to sub-class the Resolver as well. I’m fine to start going down that path, but a few questions:
- Should I be hesitant about using the (seemingly) private method
_podTemplatePatterns
above? - Is it just happenstance that the above compiles everything in my Components directory?
- Is it a bad idea to modify the resolver to accomadate this (e.g. performance impact?)
- Any other thoughts?
I’m sure I"m not the first person to try and do this – just wanted to get some input as I don’t know any other Ember developers.