pugjs / pug

Pug – robust, elegant, feature rich template engine for Node.js
https://pugjs.org
21.54k stars 1.96k forks source link

How do i change value from a variable in pugjs with javascript? #3426

Open victor-0x29a opened 4 months ago

victor-0x29a commented 4 months ago

How do i change the value from a var from pug with javascript?

mixin header(items)
    - var isEnabledDropdown = Boolean(profile?.username)
    - var title = process.env.APP_NAME
    header
        if isEnabledDropdown
            //- +dropdown(items, title)
            - var isOpenedSideSection = false
            nav.row.flex-between.svg-clickable
                h2(onclick="goToHome()").nav-title #{title}
                +hamburguer-icon("40px", "40px", "openSideSection()")
            +side-section(isOpenedSideSection, 'header')
                ul
                    if items
                        for item in items
                            li.common-header-item
                                a(href=item.href) #{item.label}

            script.
                function openSideSection() {
                    console.log(#{isOpenedSideSection}) // <- This work
                    - var isOpenedSideSection = true //  <- Doesnt work :(
                }