tj / consolidate.js

Template engine consolidation library for node.js
3.48k stars 357 forks source link

Path to pass in when using consolidate for app.engine? #301

Closed ThomasPCG closed 6 years ago

ThomasPCG commented 6 years ago

I'm doing this...

app.engine('html', engines.handlebars({
    helpers: handleBarHelpers
}));

but apparently it's failing because there is a path which I need to specify?

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot set property 'filename' of undefined

I can't find any API for the constructors above in the documentation. Can anyone guide me to the right place for this?

doowb commented 6 years ago

There's this example on the readme using express.

Also, the express documentation has a lot more information on how to use template engines. Here's a guide specifically for that

BTW... what you're doing in the code above is calling the handlebars engine directly, which is attempting to render something. Instead, just use this line:

app.engine('html', engines.handlebars);

Then see the express documentation for setting the views path and how you can pass helpers to the engine when rendering (I think you can add them as locals... app.locals.helpers = handleBarHelpers; but I'm not positive).