1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00
Files
til/rails/conditional-class-selectors-in-haml.md

22 lines
529 B
Markdown

# Conditional Class Selectors in Haml
You can assign a class selector to a tag in HAML like so:
```ruby
%div.active
```
You can conditionally assign a class selector in a concise manner like so:
```ruby
%div{ class: ( "active" if @thing.active? ) }
```
You can do multiple conditional class selectors with array syntax:
```ruby
%div{ class: [ ("active" if @thing.active?), ("highlight" if @thing.important?) ] }
```
[source](http://stackoverflow.com/questions/3453560/append-class-if-condition-is-true-in-haml-with-rails)