Closed rjurado01 closed 11 years ago
I found the response in tests:
handlebars = Handlebars::Context.new
handlebars.register_helper('method_label') do |this, context, block|
if block.call(context)
'label1'
else
'label2'
end
end
<span class="{{#method_label context}}{{method}}{{/method_label}}"> // <span class="label1">
It create span with class = context.method
Please, update documentation with it.
please see README section on helpers https://github.com/cowboyd/handlebars.rb#block-helpers thanks!
Please update README, now instead of 'call' it is necesary use 'fn'
...
block.fn(context)
...
The documentation is out-of-date and does not explain how to write block helpers with "else" conditions, which is just what this issue is created for.
Here we go, with a common use-case
handlebars = Handlebars::Context.new
handlebars.register_helper(:ifComparison) do |context, arg1, arg2, block|
if arg1 == arg2
block.fn(context)
else
block.inverse(context)
end
Thank you.
@drinor @justinperkins thanks for keeping after this. Does 31bf410 help?
Lookin good, thanks for updating Charles.
Hello,
I want to do this:
how can I add helper like this ?