Can you interpolate ruby variables within HAML css?

Viewed 7694

I need a series of classes, .module1, .module2, ... module(n).

I also want to define those classes using css, ruby and HAML:

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

Is it possible to interpolate ruby variables to save work?

.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}");
    }
2 Answers
:css
  .mod_#{extra.id}_ { 
    background-image: url("#{extra.image}");
    height: #{ruby_height}#{measure_unit_ruby_variable};
  }
Related