gpt4 book ai didi

ruby-on-rails - 你能在 HAML css 中插入 ruby​​ 变量吗?

转载 作者:数据小太阳 更新时间:2023-10-29 06:46:25 25 4
gpt4 key购买 nike

我需要一系列类,.module1, .module2, ... module(n)。

我还想使用 css、ruby 和 HAML 定义这些类:

:css
.mod1 {
background-image: url("#{extra.image}");
}

是否可以插入 ruby​​ 变量以节省工作?

.module.mod"#{extra.id}"
%h3 #{extra.title}
%p #{extra.description}
%a.btn-default{:href => "#", :target => "_top"} enter now

:css
.mod#{extra.id} {
background-image: url("#{extra.image}");
}

最佳答案

根据HAML_REFERENCE我使用了这个方法:

- flavor = "raspberry"
#content
:textile
I *really* prefer _#{h flavor}_ jam.

在 :css 之后插入变量

.module.modone{:class => "#{cycle("mod_#{extra.id}_")}"}

%h3 #{extra.title}
%p #{extra.description}
%a.btn-default{:href => "#", :target => "_top"} enter now

:css
.mod_#{extra.id}_ {
background-image: url("#{extra.image}");
background-color: #4073DF;
}

关于ruby-on-rails - 你能在 HAML css 中插入 ruby​​ 变量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6656915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com