I wrote a webform using Sinatra and Haml that will be used to call a Ruby script.
Everything seems fine except for one thing: I need to pass an argument to a Haml view f
Given
haml(template, options = {}, locals = {})
I'd try
haml :success, {}, {my_var: my_value}
I'm doing this in Sinatra+Markaby, I think it should be the same with Haml:
In Ruby script: @var = 'foo'
In template: User name: #{@var}
You can pass a hash of parameters to the Haml method using the :locals
key:
get '/' do
haml :index, :locals => {:some_object => some_object}
end
This way the Ruby code in your Haml file can access some_object
and render whatever content is in there, call methods etc.
Haml supports passing variables as locals. With Sinatra, you can send these locals like so:
haml :fail, :locals => {:vm_name => name}
and in the view, reference the variable using locals[:vm_name]
or simply vm_name
.