Closed JasonTowner closed 9 years ago
@ericf: This would be wonderful! I have struggled with the same problem. It is annoying to use the duplicate keys for Handlebars partials.
This should already be handled by specifying the partialsDir
config as an array of string paths to the component dirs: https://github.com/ericf/express-handlebars#partialsdirviewspartials
Thank you for your comment and quick response. My issue with that is that each sub-component would need to be added to the partialsDir array. So a website with 50 front-end components would all have to be added to the array. I think it's great to support that, but I also think we should add an option to do this automatically.
The code currently would have to look like this:
{
partialsDir: [
'/components/button',
'/components/error',
'/components/footer',
'/components/header',
'/components/list-block',
'/components/video',
'/components/image',
'/components/video-gallery',
'/components/image-gallery',
'/components/product',
'/components/product-list',
...etc
]
}
VS.
Using an option like the one in my pull request
{
partialsDir: '/components',
fileNameAsPartialName: true
}
We can discuss the proper name of the option as well as the proper place to do this in code, but I feel that this is something that should be included. Thoughts?
@JasonTowner you don't have to list these manually, you could use glob
:
var glob = require('glob');
// ...
app.engine('.hbs', exphbs({
extname: '.hbs'
partialsDir: glob.sync('components/*/')
}));
I think it's much more flexible to leave it open-ended and allow people to compute the array of partials dirs however they need to for their specific app. Since what you want to do is already supported, but it's just getting the array of component sub-dirs, I'd rather not add an option for that use case.
@ericf Good call, I totally spaced that part. I got so caught up on the optional param that I was blinded. Thanks!
:beers:
View README.md I added a configuration option to use the file name of the handlebar templates as the partial name regardless of directory structure. This supports having a sub-components directory structure where each sub-component is in it's own folder containing the handlebars template, scss, js, separate readme, etc. (see the screenshot below). While this is currently supported, the keys for these partials are
button/_button
anderror/_error
and this new option would set the partial keys to_button
and_error
respectively.