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

app.dynamicHelpers() #28

Open
srobbin opened this issue Mar 2, 2012 · 1 comment
Open

app.dynamicHelpers() #28

srobbin opened this issue Mar 2, 2012 · 1 comment

Comments

@srobbin
Copy link

srobbin commented Mar 2, 2012

Using other Express view engines (e.g. Jade) I am able to use [app.dynamicHelpers](http://expressjs.com/guide.html#app.dynamichelpers(\)) to make certain variables available to templates. For example:

app.dynamicHelpers({
  foo: function(req, res) { return "Foo"; }
})

is accessible in my templates as:

Hello, {{foo}}!

However, it appears that the matador.engine is not passing the dynamic helpers through to res.render.

I suspect that it's this line in matador.js, but I'm not confident enough with the source to know for sure, or to suggest a pull request:

return hogan.compile(source, options).render(options.locals, options.partials)

Inspecting options I see foo, however it is a child of options itself, and not options.locals.

@Gloorian
Copy link

Hello,

I had the same problem. I figured a solution: it's putting:
for(var i in options.app.dynamicViewHelpers) { options.locals[i] = options[i]; }

just before the line you showed us.

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

No branches or pull requests

2 participants