F
F
FlapJalc2018-12-24 14:42:53
Pug
FlapJalc, 2018-12-24 14:42:53

How to set a unique class for the last element?

Is it possible in pug/jade to assign a unique class to the last element of an array? It's kind of like last-child in css. Are there such opportunities here?

mixin breadcrumbs(...items)
  ol.breadcrumbs
    each item in items
      li.breadcrumbs__item
        a(href='#')= item

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2018-12-24
@FlapJalc

mixin list(items)
  ul.breadcrumbs
    each item, index in items
      li.breadcrumbs__item(class= (items.length === index + 1) ? 'breadcrumbs__item_last' : false )
        a(href=item.href)= item.text

+list([{href: '/one', text: 'раз'}, {href: '/two', text: 'два'}])

0
0xD34F, 2018-12-24
@0xD34F

mixin breadcrumbs(...items)
  ol.breadcrumbs
    each item, index in items
      li.breadcrumbs__item(class= items.length === index - 1 ? 'last-element' : '')
        a(href='#')= item

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question