Greg Hemphill
Greg Hemphill

Reputation: 465

Nesting items in a container using haml

I want to use an if statement to determine if items fall inside the same html container or get a new one. I can't seem to get more than one item inside the same container using haml because of the way it handles nesting.

Example:

%div.line.boards.main_boards
  - @boards.each_with_index do |board, index|
    - @board = board
    -if index == 0
      %div.unit.size1of5
    -if index <= 1
      = render :partial => "board_projects"
    -if index == 2
      %div.unit.size4of5
        = render :partial => "board_projects"

In this example the element %div.unit.size1of5 should wrap around both items index 0 & 1. However it places them after the div closes. If I indent the code where the partial is rendered so it's nested inside the div it only pulls in the index 0 item.

How is this accomplished in haml?

Upvotes: 0

Views: 444

Answers (1)

Ron
Ron

Reputation: 1166

You can pass parameters into the class of a div like so:

.unit{:class => "size#{index}"}
  = render :partial => "board_projects"

And then make it a CSS problem instead of a Ruby/HAML one.

Upvotes: 1

Related Questions