Answer the question
In order to leave comments, you need to log in
How to write a mixin for Jade/Pug?
Hey! How to write a mixin correctly, having the condition that in any of the li there may be another ul list.
Now I wrote this mixin:
mixin benefits-product(title, ...items)
+b.each-product
+e('ul').list #{title}:
each item in items
+e('li').item--benefits #{item}
+e('li').item--benefits #{item}
+e('ul').list--benefits
each item in items
+e('li').item--benefits #{item}
Answer the question
In order to leave comments, you need to log in
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)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question