Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an image to the contents using HAML?

Tags:

New to this tagging language, and I'm having trouble finding documentation mentioning how to work with images. An example or two would be fantastic.

Btw, I did refer to this discussion, but not sure if that's what I need.

like image 203
stanigator Avatar asked May 12 '12 04:05

stanigator


People also ask

How to add a div in Haml?

In Haml, we write a tag by using the percent sign and then the name of the tag. This works for %strong , %div , %body , %html ; any tag you want. Then, after the name of the tag is = , which tells Haml to evaluate Ruby code to the right and then print out the return value as the contents of the tag.

How to Use Haml in Rails?

To use Haml with Rails, simply add Haml to your Gemfile and run bundle . If you'd like to replace Rails's Erb-based generators with Haml, add haml-rails to your Gemfile as well.


1 Answers

Outside any kind of framework:

%img(src="/images/loading.gif") 

The older, more verbose but flexible syntax:

%img{:src => "/images/loading.gif"} 

If you’re using Rails, it will generate the tag itself:

=image_tag "loading.gif" 
like image 176
Buck Doyle Avatar answered Oct 04 '22 23:10

Buck Doyle