How to write a mixin for Jade/Pug?

Hi! How to write a mixin, with the condition that any of the li may be another list ul.
Now they have written a mixin:
mixin benefits-product(title, items...)
+b.each-product
 +e('ul').list #{title}:
 each item in items
 +e('li').benefits--item #{item}
 +e('li').benefits--item #{item}
+e('ul').list--benefits
 each item in items
 +e('li').benefits--item #{item}


We1bi.png

But it is not true.
July 8th 19 at 11:43
1 answer
July 8th 19 at 11:45
Solution
Recursion
codepen.io/Zoxon/pen/zBPBbW?editors=1000#0

{
 "title": "Title text",
 "items": [
{
 "title": "Item 1"
},
{
 "title": "Item 2",
 "sublevel": true,
 "items": [
{
 "title": "Item 2.1"
},
{
 "title": "Item 2.2"
},
{
 "title": "Item 2.2",
 "sublevel": true,
 "items": [
{
 "title": "Item 2.2.1",
 "sublevel": true,
 "items": [
{
 "title": "Item 2.2.2.1"
},
{
 "title": "Item 2.2.2.2"
},
{
 "title": "Item 2.2.2.3"
}
]
},
{
 "title": "Item 2.2.2"
},
{
 "title": "Item 2.2.3"
}
]
}
]
},
{
 "title": "Item 3"
}
]
}


mixin list(data)
ul
 each item in data.items
 li= item.title
 if item.sublevel
 +list(item)


You can even remove the sublevel and do background checks on nested items

Find more questions by tags Pug