F
F
FlapJalc2018-12-25 18:16:31
Pug
FlapJalc, 2018-12-25 18:16:31

How to output data from json file array to pug loop?

I have an array with data in json format

{
  "socialsData":
  [
    {
      "title" : "Вконтакте",
      "prefix" : "vk",
      "href" : "https://vk.com/"
    },
    {
      "title" : "Фейсбук",
      "prefix" : "fb",
      "href" : "https://fb.com/"
    }
  ]
}

In the gulp file, I specify where to parse the json file
.pipe(pug({
      locals : {
        socials: JSON.parse(fs.readFileSync('src/modules/socials/socials.json', 'utf8')),
      }
     }))

In the socials.pug file, I output data in a loop
ul.socials
  each href, title, prefix in socials.socialsData
    li.socials__item
      a(href= '' +href target="_blank" class= 'socials__link socials__link--' +prefix)= title

But I have 0, 1, ... displayed instead of title. I understand that the output from the array should be somewhat different, and therefore I do not get the expected result. How can I correctly display the elements of an array in a loop?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
monochromer, 2018-12-25
@FlapJalc

each item in socials.socialsData
  a(href=item.href) #{item.title}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question