Skip to content
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

exposing a nested object to a layout #32

Closed
tommedema opened this issue Aug 21, 2013 · 2 comments
Closed

exposing a nested object to a layout #32

tommedema opened this issue Aug 21, 2013 · 2 comments
Labels

Comments

@tommedema
Copy link

As far as I am aware only helpers can expose a variable to a layout (and therefore every request).

I want to expose a config object such that I can access its nested properties in layout.handlebars. I did this:

server.engine('handlebars', exphbs({
    defaultLayout: 'main',
    layoutsDir: config.http.web.layoutsDir,
    helpers: {
        config: function() { return config; }
    }}));

And layout.handlebars:

<footer>
    <p>MyApp version {{{config.version}}}.</p>
</footer>

Unfortunately this doesn't work. Why not? Is there any way to expose a nested object to every layout/view such that I can access its properties everywhere?

@ericf
Copy link
Owner

ericf commented Aug 21, 2013

Are you using Express' Locals system to create the context in which your templates are rendered?

There's both app.locals and res.locals, and this is how data is exposed to templates. Both layouts and views will be rendered with this data.

@tommedema
Copy link
Author

Cool, that's much better than using a helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants