handlebars-iron icon indicating copy to clipboard operation
handlebars-iron copied to clipboard

Ability to access request extensions in Helpers

Open untitaker opened this issue 7 years ago • 2 comments

I want to be able to access the current request (in particular the extensions field) from within the template helpers I registered. The end goal is to make url_for from iron-router available in templates.

I realize that this is extremely hard and I'm not sure if handlebars-iron is even supposed to solve it. Flask solves the general problem by adding threadlocals everywhere, but I don't think that's the way to go for a framework and language where performance, control and data flow is more explicit than elsewhere.

untitaker avatar Sep 18 '16 13:09 untitaker

Well, the Context object is design to pass data to templates. So I think you can put the request data into context can access it from helper. To make it elegant perhaps we can design an Iron middleware to put some Request data into context.

I have an undocumented project https://github.com/sunng87/handlebars-template-handler you might be interested in.

sunng87 avatar Sep 18 '16 15:09 sunng87

Would there be a possibility to throw arbitrary types onto Context as well, in the style of request.extensions? Right now I would need to serialize data to JSON and back.

Probably would only be usable from helper functions, not directly from the template.

On Sun, Sep 18, 2016 at 08:24:58AM -0700, Ning Sun wrote:

Well, the Context object is design to pass data to templates. So I think you can put the request data into context can access it from helper. To make it elegant perhaps we can design an Iron middleware to put some Request data into context.

I have an undocumented project https://github.com/sunng87/handlebars-template-handler you might be interested in.

You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/sunng87/handlebars-iron/issues/51#issuecomment-247854006

untitaker avatar Sep 19 '16 17:09 untitaker