I was evaluating Slim as a replacement for HAML in a personal project, and it doesn\'t appear to handle HTML5 data attributes as gracefully as
Use the splat operator:
h1#section-title*{'data-url'=>'test', 'data-id'=>'test'} = @project.name
I prefer this kind to fix...
@products.each do |product|
.module data-id=product.id
It is working for me
.your-class*{data: {first_attribute: 'first value', second_attribute: 'second value'} }
Will produce
<div class="your-class" data-first_attribute="first value" data-second_attribute="second value"></div>
There are multiple ways in Slim
As Hash
Attributes which will be hyphenated if a Hash is given (e.g. data={a:1,b:2} will render as data-a="1" data-b="2")
Use it directly as "mu is too short" mentioned, quite intuitive.
a data-title="help" data-content="foo"
Use Ruby code. I often do this and rarely above.
= link_to 'foo', bar_path, data: {a: 'a', b: 'b'}