D
D
DeniSidorenko2017-09-22 17:34:37
Pug
DeniSidorenko, 2017-09-22 17:34:37

How to create a mixin in pug to display products of the same type?

Hello, I switched to jade. There was a need to use its ability to create mixins or mb functions, I don’t know exactly what the name is. So here's the thing, as I know, you can create "this" and then call it only by specifying other data as in a function. I'll show an example on the screen
12b73550eb.jpg
Here there are several blocks, they differ only in the image, price and quantity. You can create a mixin and simply call it each time with the parameters you need. I hope you understand what I mean.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2017-09-22
@werty1001

mixin product( data )
  .product
    .product__name= data.name
    .product__cost= data.cost

//- Один
+product( {name: 'Шоколадка', cost: '3$'} )

//- Несколько
each item in [{name: 'Шоколадка', cost: '3$'}, {name: 'Мороженка', cost: '1$'}]
  +product( item )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question