K
K
Kristina Konstantinova2018-10-19 14:42:14
Pug
Kristina Konstantinova, 2018-10-19 14:42:14

How to write a mixin for a list in pug with a condition?

there is a mixin

mixin tovar(name, list, kg)
  .tovar__item.tovar__item--basis
    .tovar__main
      .tovar__info
        .tovar__title.
          Нямушка 
          #[span= name]
        ul.list
          each item in list
            li= item.text
        button.button.
          #[span= kg]
          кг

I call it like this:
+tovar('Название', [{text: "Один"}, {text: 'Два'}, ], '0.5')

The issue is that some li's may contain a span with a value of , and some may not. How to implement it?
For example:
<ul>
   <li><span>10</span> порций</li>
   <li>мышь в подарок</li>
</ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2018-10-19
@Kris_del

mixin tovar(name, list, kg)
  .tovar__item.tovar__item--basis
    .tovar__main
      .tovar__info
        .tovar__title Нямушка #[span= name]
        ul.list
          each item in list
            li
              if item.num
                span= item.num
              |  #{item.text}
        button.button #[span= kg] кг

// call
+tovar('Название', [{num: 10, text: "порций"}, {text: 'мышь в подарок'}, ], '0.5')
//

https://codepen.io/werty1001/pen/XxqyRX

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question