'Pug - pass json data from pug to pug
What i want to do is to pass a json data and loop it in other pug, but there was some errors.
Pug 1
-
var json = [
{type:"2", shareTools:"true", id:12},
{type:"1", shareTools:"false", id:20}
]
include pug2.pug
Pug 2
div.json #{json}
each data in json
li= data.type
Here is the html output of div.json #{json}
[object Object],[object Object]
gulp error message
> 4| each data in json
Cannot read property 'length' of undefined
Thanks.
Solution 1:[1]
Hi, hope this helps
Changed 2nd row in pug2.
Pug1
-
var jsonnn = [
{type:"2", shareTools:"true",
id:12},{type:"1", shareTools:"false", id:20}
]
include pug2
Pug2
div.json #{json}
each data, i in jsonnn
li= data.type
Solution 2:[2]
From a style point of view, a mixin might be worth considering.
Pug1:
include mixin1
-
var data_set = [
{type:"2", shareTools:"true",
id:12},{type:"1", shareTools:"false", id:20}
]
mixin1(data_set)
Pug 2 is the mixin:
mixin mixin1(data_set)
each data in data_set
li= data.type
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dave |
| Solution 2 | Donald Koscheka |
