F
F
FlapJalc2018-12-24 14:36:32
Pug
FlapJalc, 2018-12-24 14:36:32

How to display element references in a loop?

There is a mixin that outputs a list through a loop. How can I make it so that each element can be assigned a link corresponding to it? Now for all elements, # is used as a link, but I need to be able to independently set a specific page for each link.

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

+list(1,2,3)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-12-24
@FlapJalc

mixin list(...items)
  ul.breadcrumbs
    each item in items
      li.breadcrumbs__item
        a(href=item)= item


+list('https://www.google.ru/', 'https://toster.ru', 'https://toster.ru/q/590329')

or, if items are not full references but parameter values:
mixin list(...items)
  ul.breadcrumbs
    each item in items
      li.breadcrumbs__item
        a(href='https://toster.ru/q/' + item)= item

+list(590329, 588072, 584712)

or if you want text and link to be different:
mixin list(...items)
  ul.breadcrumbs
    each item in items
      li.breadcrumbs__item
        a(href=item.link)= item.text


+list({ link: 'https://www.google.ru/', text: 'google' }, { link: 'https://toster.ru', text: 'toster' }, { link: 'https://toster.ru/q/590329', text: 'ваш вопрос' })

O
Oleg, 2018-12-24
@werty1001

mixin list(items)
  ul.breadcrumbs
    each item in items
      li.breadcrumbs__item
        a(href=item.href)= item.text

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question