ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

Issues with Metadata #153

Open custa1200 opened 8 years ago

custa1200 commented 8 years ago

Hi the following that I have set in app.js do not seem to be available to my templates since I switched to express-handlebars

app.locals.siteUrl = config.get('site.url');
app.locals.siteName = config.get('site.name');
app.locals.siteTitle = config.get('site.title');
app.locals.siteEmail = config.get('site.email');
app.locals.socialSiteIcon = config.get('social.siteIcon');
app.locals.socialLinkedinUrl = config.get('social.linkedinUrl');

This is an example of siteTitle that I have in a handlebars template in my site.

<title>{{title}} - {{@siteTitle}}</title>

If I just do a console.log underneath where they are assigned the correct value gets put to the console, so it is reading them into the locals fine.

custa1200 commented 8 years ago

When I used the handlebars (hbs) that ships with ExpressJS I just had to add the following to my app.js

hbs.localsAsTemplateData(app);

But if I add that using handlebars-express it causes an error.

custa1200 commented 8 years ago

This is an absolute show stopper for using Express Handlebars and judging by same issue in #136 being around for almost 6 months it's very concerning. Is there any known workaround for this? otherwise I am going to have to go back to the builtin handlebars. :(

loganfuller commented 8 years ago

Locals don't require the @ symbol.

Example: https://github.com/ericf/express-handlebars/blob/master/examples/advanced/views/partials/page/title.handlebars

custa1200 commented 8 years ago

This deviates from the way the shipping handlebars (hbs) handles app.locals.x and quite clearly causes confusion. I don't think this is a good pattern.

https://github.com/donpark/hbs#exposing-locals-as-template-data