Using ruby array/hash in HAML?

1,933 views
Skip to first unread message

Shaz

unread,
Apr 8, 2010, 7:59:05 AM4/8/10
to Haml
I have in ruby:

@data =
--> {"name"=>["one", "two", "three"], "content"=>["content for 1",
"content for 2", "content for 3"]}

And I want to call it in HAML:

%html
%head
%body
#outer
#navigation
%ul.navigation
-@data["name"].each do |name|
%li
%a(href="\##{name}") #{name}
#content
-...@data.each do |name, content|
.panel(id="#{name}")
#{content}

Essentially be able to show the content with the name?

Yehuda Katz

unread,
Apr 8, 2010, 8:52:04 AM4/8/10
to haml
You should be able to use any Ruby expression in the Hash portion:

%html
 %head
 %body
 #outer
  #navigation
   %ul.navigation
    - @data["name"].each do |name|
      %li
        %a{:href => "\##{name}"}= name
  #content
   - @data.each do |name, content|
    .panel{:id => name)
       = content

Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325



--
You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.


Reply all
Reply to author
Forward
0 new messages