R
R
RedSmoke_smr2019-04-30 13:52:24
HTML
RedSmoke_smr, 2019-04-30 13:52:24

How to specify a condition for a link in PUG?

Good afternoon, please tell me how in PUG to make the href="index.html" attribute of the link appear only when there is a variable on the page - var pageClass = 'index-page', otherwise the link should not be href ?
I only managed to implement it this way, but it doesn’t quite suit me, it turns out extra repetitive code. Is there any way to reduce this code? Thanks in advance for your reply)

if pageClass !== 'index-page'
            a(href='index.html').main-nav__logo
        else
            a.main-nav__logo

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2019-04-30
@RedSmoke_smr

a.main-nav__logo(href = pageClass == 'index-page' ? false : 'index.html')

If you plan to use it in several places, then put it in a mixin, of course.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question