V
V
Vadim V2018-05-23 19:38:17
JavaScript
Vadim V, 2018-05-23 19:38:17

How to get object from JS in Pug?

Help me understand, here I got an object in JS const friends = await callAPI('friends.get', { fields: 'city, country, photo_100' }); which contains a list of friends in VK. How can I get this object and use it in PUG to display all friends in the each avatar loop, name in friends for example. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Taratin, 2018-05-23
@reyzele

ul
  each f in friends 
    li= f.name + f.avatar

friends can be passed as a local variable
//Для nodejs
const compiledFunction = pug.compileFile('template.pug');

//Для webpack при подключеном pug лоадере
const compiledFunction = require('template.pug');

const friends = await callAPI('friends.get', { fields: 'city, country, photo_100' });

console.log(compiledFunction({
  friends 
}));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question