user3007294
user3007294

Reputation: 951

Iterating in Slim

say I have an array of strings

array = ["one","two","three","four","five","six","seven","eight","nine","ten"]

I need to create a Slim structure such as this:

      li
        a href="#slide1"
          -puts "one"
          -puts "two"
          -puts "three"
          -puts "four"
          -puts "five"

      li
        a href="#slide2"
          -puts "six"
          -puts "seven"
          -puts "eight"
          -puts "nine"
          -puts "ten"

The problem I'm having is creating an iteration in which the first five strings in the array are put under '#slide1' and then once six hits, a new li is creating and the remaining array strings are housed under '#slide2'.

Can this be down?

Upvotes: 1

Views: 3353

Answers (1)

Amadan
Amadan

Reputation: 198436

- array.each_slice(5).each_with_index do |slice, i|
  li
    a href="#slide#{i + 1}"
    - slice.each do |item|
      = item

Upvotes: 6

Related Questions