Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate over an array with HAML?

Tags:

iteration

ruby

I have this in a HAML layout (layout.haml)

- @fonts.each do |font|
  %link{:href=>"//fonts.googleapis.com/css?family={font}",:rel=>"stylesheet",:type=>"text/css"}

And I have this in the HAML template index.html.haml

- @fonts = ['Lato:400,300,100','Droid+Serif:700,400'];

When I compile, I get this:

<link href='//fonts.googleapis.com/css?family={font}' rel='stylesheet' type='text/css' />
<link href='//fonts.googleapis.com/css?family={font}' rel='stylesheet' type='text/css' />

What am I doing wrong?

like image 743
mrbinky3000 Avatar asked Feb 02 '12 19:02

mrbinky3000


1 Answers

You forgot the hash symbol.

- @fonts.each do |font|
  %link{:href=>"//fonts.googleapis.com/css?family=#{font}",:rel=>"stylesheet",:type=>"text/css"}
                                                  ^ here
like image 105
Sergio Tulentsev Avatar answered Oct 13 '22 00:10

Sergio Tulentsev