ibpix
ibpix

Reputation: 319

how to conditionally add a div in slim

I have a small html fragment and want to write a conditional such that the first two loading results are wrapped in a div called "loading-top-two" but not sure how to do it. Was thinking something like this but (obviously) doesn't work. How would I do this? On RoR, if there's any magic to be had there.

.loader-results
  - (0..2).each do |i|
    - if i==0
      .loading-top-two
        = render "lawyers/search/loading_result", idx: i
    - else
      = render "lawyers/search/loading_result", idx: i

Upvotes: 0

Views: 561

Answers (1)

Eyeslandic
Eyeslandic

Reputation: 14900

If I understand correctly you can just do this, first render the first two and then the rest of the result. [2...] means everything from the item with index = 2 until the end (infinity)

.loading-top-two
  - @result[0..2].each_with_index do |result, index|
    = render "lawyers/search/loading_result", idx: index

- @result[2...].each_with_index do |result, index|
  = render "lawyers/search/loading_result", idx: index

Upvotes: 1

Related Questions