Lolo Lolo - 1 month ago 9
Node.js Question

JADE : Can't generate mixin with an array

I try to generate a code from a mixin which use an array :

- var tabList = [
{
data: "data-toggle",
href: "#pp",
text: "All"
},{
data: "data-toggle",
href: "#pp",
text: "Popol"
}
];


mixin generateTabs(tabs)
h1 tabs
ul
each tab in tabs
li=tab.text


+generateTabs(tabList)


When I try to compile it I have

dev\jade\test.jade:2
1| - var tabList = [
> 2| {
3| data: "data-toggle",
4| href: "#pp",
5| text: "All"

unexpected text {


I'm using Node 6.3.1, gulp-jade 1.1.0

QoP QoP
Answer

You almost got it right, you have to use a proper indentation.

-
 var tabList = [
    {
        data: "data-toggle",
        href: "#pp",
        text: "All"
    },{
        data: "data-toggle",
        href: "#pp",
        text: "Popol"
    }
 ];


mixin generateTabs(tabs)
    h1 tabs
        ul
            each tab in tabs
                li=tab.text


+generateTabs(tabList)

codepen

Comments