Partials ignore express' views folder #86

wants to merge 1 commit into


None yet
3 participants

Following situation:


app.engine('html', cons.handlebars);
app.set('views', __dirname + '/views');

res.render('account/edit', {partials: {
  head: '_head'

→ Consolidate looks for Appfolder/views/account/_head.html instead of Appfolder/views/_head.html which is the default views folder we defined earlier.

This is in my eyes pretty unfavorable because we don't have a chance to define "default" partials using app.locals() since the folder consolidate is looking for templates differs for every view and depends on the folder the currently compiled template is placed in.

In my version consolidate checks if a default views folder was defined and if so, loads the partials from there instead of from the current path.

app.locals({partials: {head: '_head'}}); then always looks for Appfolder/views/_head.html and ignores the current working dir which makes life much easier.

did this ever get decided upon - in or out? +1 from me. header and footer use case seems compelling


doowb commented Sep 17, 2017

I know it's been a long time, but if anyone is still interested in this change, I think it can be useful with the following changes:

  • instead of options.settings.views use options.partialsDir
  • if partial doesn't exist in options.partialsDir fallback to dirname(path) for backwards compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment