-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for array as views #126
base: master
Are you sure you want to change the base?
Conversation
Adds a new private function _getView, that - if viewsPath is an array - compares it to viewPath stripped of the filename, and then does the usual _getTemplareName().
} | ||
|
||
var self = this; | ||
var stripFilename = /\/[^\/\\]+?$/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work with Windows.
I'm actually wondering if getting the view's "name" (the value passed to I'm not sure what should be considered the best match. We can use |
var stripFilename = /\/[^\/\\]+?$/; | ||
|
||
// Stripping filename (rather than indexOf) in case there are | ||
// multiple views folders in the same parent directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is why we need a criteria for determine the best match. Should we go with, the file must exist in the dir, and have the shortest length to be the winner?
Ah, so if there happen to be multiple .handlebars files named the same thing in different views? Perhaps an error message asking one of them to be renamed, or giving each a unique name, e.g. |
Something like this? path.normalize should take care of the backslash issue, but I'll see if I can test it tomorrow as well.
If you have the following views dirs:
And the view that's being rendered is at: Using
Using
So the question is which one of these do you pick? Is it simply the shortest one? I think that in this case it would be reasonable to pick |
Yeah, that's why I used the strip-filename regex. With those three views dirs, you'd only get one possibility: |
Nope it can't because no matter what's specified to |
Is this fixed? |
Taking a step back: much of this would be resolved if |
Is there any update/decision on this? Restricting to a single views folder is really quite limiting. |
Just ran into this issue today as well, would also like to know if there are any updates. |
I really need this feature too. @ericf are you planning to merge this? are you waiting for something? |
Also really need this feature. I noticed after going through express-handlebars.js that nothing seems to need the My question is: Is there any reason I shouldn't be pulling out the view property of the options object? |
Any updates on this? Did anyone cloned this repo and merged this...? |
Development has moved to https://github.com/express-handlebars/express-handlebars/ if you would like to create a PR on that repo we could add this. |
Fixes #124.
I've added a fix based on your help, and now when views is an array, res.render checks both folders (I've tested). I've tried to match the existing codebase/style as closely as possible, but there's probably still a few things you can fix (like the
_getView
comment).Hope it's good enough!