I'm trying to create a haml template that uses some data from my ruby app to fill in some content. Is it possible to pass arguments into haml to make it render correctly? Here's how I'm getting my haml template and rendering it:
template = File.open('path/to/template.haml')
html = Haml::Engine.new(template.read).render
So, is it possible to pass objects from the local Ruby script into the template file so that they the page is rendered correctly? Or, can I have the haml file pull in objects?
If this doesn't work, my only other idea is building up the template as a local string which seems more tedious to me. So, is there a different coding pattern that is more efficient for this job?
Yes,
Check the docs: http://haml.info/docs/yardoc/Haml/Engine.html#render-instance_method
pass them as locals
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With