1

I can eazy return the current admin in view after use PassportJs to authenticate by this

dashboard(req,res,next){          
    var CurentAdmin = req.user.adminname
    res.render('admin/dashboard',{layout:'admin',CurentAdmin})
}

And just call "CurentAdmin" in this view

But i want to show the current admin have logged in in a layout template. How can i do it.

This is a part of file layout "admin.handelbars"(a layout not a view)

<div class="admin-detail">                         
    <p class="admin-name">{{ Current Admin must be here }}</p>
    <i class="admin-icon fas fa-chevron-down"></i>
    <div class="admin-actions">
       <div class="admin-logout">Đăng xuất</div>
    </div>
</div>
Leland
  • 2,019
  • 17
  • 28
Thi Đình
  • 11
  • 1
  • Does this answer your question? [How to set a variable for the main handlebars layout without passing it to every route?](https://stackoverflow.com/questions/25095991/how-to-set-a-variable-for-the-main-handlebars-layout-without-passing-it-to-every) – 76484 Oct 09 '21 at 12:25

1 Answers1

0

change:

res.render('admin/dashboard',{
    layout:'admin',
    CurentAdmin: req.user.adminname
});

In tempale:

<p class="admin-name">{{CurentAdmin}}</p>
Dũng IT
  • 2,751
  • 30
  • 29