在haml中使用div title语法,并在其中包含ruby变量

nhjlsmyf  于 12个月前  发布在  Ruby
关注(0)|答案(3)|浏览(92)

我在将HTML语法转换为HAML时遇到了问题。
我知道<div>类可以简单地表示为:

.class-name

但是,我想将以下语法转换为HAML,并在标题中加入一个变量:

<div title="My title" class="my-text">This is my title</div>

例如:

.title{@ruby-variable}.my-text
d4so4syb

d4so4syb1#

.my-text{:title => "My title"} This is my title

在Haml中使用#someid.someclass{:custom_attr => "something"}:costum_attr也可以是一个类或一个id,如果你需要动态定义它。

roejwanj

roejwanj2#

试试这个:

.my-text{:title => 'My title'} This is my title

或者另一种语法:

.my-text(title = 'My title') This is my title
lstz6jyr

lstz6jyr3#

更现代的语法是.my-text{title: 'My title'} My text.

相关问题