iterate over an array of objects in jade/pugjs
Asked Answered
O

2

15

I have the following json object:

 var partners =[{ "name":"partnerx", "image": "imagex" }, { "name": "partnery", "image": "imagey" }]

I want to put into a ul object using jade and I tried:

ul#slides.swiper-wrapper
   mixin partners(name, image)
    li.swiper-slide
       img(src=#{image} , alt=#{name})

This is not working.

Omasum answered 19/6, 2014 at 21:48 Comment(0)
C
27

Try this:

ul#slides.swiper-wrapper
   each partner in partners
     li.swiper-slide
       img(src=partner.image, alt=partner.name)

https://pugjs.org/language/iteration.html

Clino answered 19/6, 2014 at 22:14 Comment(1)
How to iterate over an array of objects in jade/pugjs inside .script ?Otila
D
1

You can also access the property using brackets

ul#slides.swiper-wrapper   
 each partner in partners
  span #{partner.name}
Droop answered 15/12, 2021 at 23:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.