简体   繁体   中英

How to iterate over an array with HAML?

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?

You forgot the hash symbol.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM