Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iterate over an array of objects in jade/pugjs

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.

like image 977
hopper Avatar asked Jun 19 '14 21:06

hopper


1 Answers

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

like image 71
tpae Avatar answered Nov 05 '22 21:11

tpae