Mechwd
Mechwd

Reputation: 400

HAML, Add class to image_tag

I have

= image_tag  "chart.jpg"

I am new to HAML so how do I add a class to this?

Upvotes: 19

Views: 18124

Answers (2)

Sketchybear
Sketchybear

Reputation: 67

Stumbled across this answer when I was looking for something else and thought I'd throw in a little update to use the more modern formatting :)

=image_tag 'chart.jpg', class: 'my_class'

Upvotes: 5

matt
matt

Reputation: 79783

Assuming this is rails (Haml doesn't have its own image_tag helper, but Rails does), then the second argument is an options hash where you can specify the class:

=image_tag  "chart.jpg", :class => "my_class"

Upvotes: 36

Related Questions