Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAML, Add class to image_tag

Tags:

haml

I have

= image_tag  "chart.jpg"

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

like image 941
Mechwd Avatar asked Sep 10 '11 01:09

Mechwd


2 Answers

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"
like image 59
matt Avatar answered Oct 31 '22 00:10

matt


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'

like image 20
Sketchybear Avatar answered Oct 30 '22 22:10

Sketchybear