Answer the question
In order to leave comments, you need to log in
How to get data from json file in pug template?
Have a file structure
|--blocks
|--block.pug
|--block.json
ul.blocks
each link, title in blocksData
li.blocks__item
a(href="link")= title
{
"blocksData": {
"Ссылка 1" : "/link1",
"Ссылка 2" : "/link2",
"Ссылка 3" : "/link3"
}
}
Answer the question
In order to leave comments, you need to log in
json must first be converted to data outside the template engine
var pug = require('pug');
var fn = pug.compileFile('path to pug file', options);
var locals = require('./block.json');
var html = fn(locals);
var pug = require('pug');
var fn = pug.compileFile('path to pug file', options);
var html = fn({'req': require});
=====
//pug file
- var menu = req('./block.json')
ul.blocks
each link, title in menu.blocksData
li.blocks__item
a(href="link")= title
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question