D
D
Dima2018-02-13 16:24:51
Pug
Dima, 2018-02-13 16:24:51

How to iterate values ​​from an array in different elements in PUG?

There is a construction like this, which is repeated 10 times:

.sidebar__tags-item
      a(href="#") #tag
      span 10

Values ​​into elements aand spanI want to take from an array of the form:
- var tags = ["#life", "#weekend", "#thoughts"]
- var tagsCount = ["10", "20", "30"]
As a result, it turns out like this
include data.pug

.sidebar__tags-item
  a(href="#") !{tags[0]}
  span !{tagsCount[0]}
...

But how can I loop it so that I have 10 such blocks, and each would have different values ​​\u200b\u200bfrom the array? If we take the usual loops from the documentation, then all values ​​will be generated in one element .sidebar__tags-item, and I need 10 with different values ​​from the array. And is this even possible? :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2018-02-13
@qpz

each tag in [{name: '#life', num: '10'}, {name: '#weekend', num: '10'}, {name: '#thoughts', num: '10'}]
  .sidebar__tags-item
    a(href='#')= tag.name
    span= tag.num

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question