Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
How to send variable to partial in express(nodejs) to handlebars

I want to add profile section in my application, So for this i have to pass a session email as a variable to partial navbar, so that when someone login in it the email will pass to partial, and now if clicked on profile then it will go to specific person profile section.

please tell me the solution for this solution or suggest any another way to do this.

In nabar.hbs(partial)

<nav class="navbar">
    <ul class="nav-items">
        <li><a href="/">Home</a></li>
        <li><a href="/contact">Contact</a></li>
        <li><a href="/about">About</a></li>
    </ul>

    <ul class="for-login">
        {{#if login}}
        <li><a href="/profile/{{email}}">Profile</a></li>
        <li><a href="/logout">Logout</a></li>
        {{/if}}
        {{#unless login}}
            <li><a href="/login">Login</a></li>
            <li><a href="/signup">SignUp</a></li>
        {{/unless}}
    </ul>
</nav>

In app.js:

app.post('/login', async(req, res)=>{

    try{
        var email = req.body.email;
        var password = req.body.password;
        console.log(email);

        const useremail =  await Register.findOne({email:email});
        const isMatch = await bcrypt.compare(password, useremail.password);
        if(isMatch){
            sess = req.session;
            sess.name = useremail.name;
            sess.email = useremail.email;
            res.status(201).redirect('/');
        }
        else{
            res.status(400).send("INVALID LOGIN CREDENTIALS");
        }
    }
    catch(error){
        console.log(error);
    }

});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!