2

I'm learning pug, and after reading a comment here and adjusting it slightly, I got this Mixin:

mixin mainnav(i)
    ul
        li(class=(!--i) && "active")(class='home')
            a(href="/") Home
        plus other li's,

Then:

+mainnav(1)

To create this html:

<nav class="main-nav">
   <ul>
      <li class="active home"><a href="/">Home</a></li>
      other li's...

It creates what I want, and you can move the 'active' class by changing the +mainnav(x), but there is a warning on compile:

'You should not have pug tags with multiple attributes.'

Is there a cleaner way to do this?

(I looked at the solution here - and tried

li(class="home" && (!--i) && "active")

but only 'active' got added as a class.)

1 Answer 1

1

This should work just fine:

li.home(class= (!--i) && "active")
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.