sunng87 / handlebars-iron

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

Calling a function from a template #65

Closed GildedHonour closed 6 years ago

GildedHonour commented 6 years ago

How can I call my own custom function from a template?

sunng87 commented 6 years ago

You will need to define a helper for that. Also you can call that function before rendering the template, and pass the result data into the template.

GildedHonour commented 6 years ago

I can't call it before, I'll need to call it from a template. In the "examples" there's no such an example, is there one?

GildedHonour commented 6 years ago

I can't call it before, I'll need to call it from a template. In the "examples" there's no such an example, is there one?

sunng87 commented 6 years ago

There is an example here https://github.com/sunng87/handlebars-iron/blob/master/examples/server.rs#L104

You can define a helper like some_helper and put your function in. Then call it from your template by something like {{some_helper 1 2 3}}.

For example of handlebars helper, you can find here: https://github.com/sunng87/handlebars-rust/blob/master/examples/render.rs#L13