I know how to create a link with a data-* attribute:
%a{ :href => "#", :data => { :name ="John", :age => 24 } } Hi John
generates:
<a href="#" data-name="John" data-age="24">Hi John</a>
But how about a 2 deep data name, like data-user-name
and data-user-age
, a way to group data attributes. As you may guess, I tried:
:data => { :user => { :name => "John", :age => 24 } }
But it doesn't work, giving me strange HTML output:
<a href="#" data-user="nameJohnage24">Hi John</a>
Any idea how to do that? Thanks in advance.
You'll have to use
:data => {'user-name' => 'John', 'user-age' => 24}
The data
attribute is special-cased by HAML and it only accounts for shallow values.
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