handlebars_assets icon indicating copy to clipboard operation
handlebars_assets copied to clipboard

Accessing View Helpers From Templates

Open Undistraction opened this issue 12 years ago • 1 comments

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.

Undistraction avatar Dec 04 '13 13:12 Undistraction

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).

AlexRiedler avatar Dec 04 '13 19:12 AlexRiedler