leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
649 stars 159 forks source link

Accessing View Helpers From Templates #89

Open Undistraction opened 10 years ago

Undistraction commented 10 years ago

It seems that view helpers are not directly available in .hbs.erb templates? Or am I missing something?

I have managed to access them using:

<% environment.context_class.instance_eval { include ExampleHelper } %>

But it would be great if they were available directly.

AlexRiedler commented 10 years ago

So View Helpers generally access non-constant data, and since handlebar files (.hbs) are in the asset pipeline (can be precompiled etc), they have no concept of a 'view'; as a result they do not include the View Helper.

I am hoping this explains why they are not directly available; and potentially why it does not make sense to add them. I am up for debate over this, just a question of how you would go about choosing the correct helper given a template file name? (edit) Assuming it is possible (end-of-edit).