74
63

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

haml に HTML5 のカスタムデータ属性(data-*) を定義する方法

Posted at

例えば、

<div data-id=“hoge”></div>

と定義したいときに、haml に

%div{data-id: “hoge”}

と書くと実行時に

syntax error, unexpected tLABEL
...ut.attributes({}, nil, data-id: "hoge")}></div>\n", 0, false...

と文法エラーになる。

解決方法

%div{data: {id: "hoge"}}

というように、- で区切ってハッシュを定義すれば、

<div data-id="hoge"></div>

となる。

参考

74
63
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
74
63

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?