V
V
Vadim V2018-04-18 22:51:15
Pug
Vadim V, 2018-04-18 22:51:15

How to access the first element of each loop in pug?

each index in items
  li.blog-nav__item= index.title

How can I put the class active on the first item. That is, what would only the first element receive always the active class?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Belkin, 2018-04-18
@reyzele

I found this option in my old code

ul.breadcrumb
        each item, i in items
            li.breadcrumb__item
                if i < items.length - 1
                    a.breadcrumb__link(href="#") #{item}
                else
                    span.breadcrumb__link.current #{item}

I think you can change it to this
each item, index in items
  if index == 0
    li.blog-nav__item.active= item.title
  else
    li.blog-nav__item= item.title

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question