sunng87 / handlebars-iron

Handlebars middleware for Iron web framework
MIT License
119 stars 20 forks source link

Ability to access request extensions in Helpers #51

Open untitaker opened 7 years ago

untitaker commented 7 years ago

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.

sunng87 commented 7 years ago

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.

untitaker commented 7 years ago

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