HAML: Create data-xxx-yyy attribute
11,291
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.
Related videos on Youtube
Comments
-
htaidirt over 1 year
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
anddata-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.
-
htaidirt almost 12 yearsSo, it's not possible to group
user-
the way we groupeddata-
? -
Casey Foster almost 12 yearsNo, because the
data
attribute is special-cased by HAML and it only accounts for shallow values. You could open an issue at github.com/haml/haml to spark some discussion on it. I didn't look but I wouldn't be surprised if it had been mentioned before.