Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
How to pass information from a controller to a partial view

I'm having a problem with express and I don't know how to fix it. I would like to be able to pass information from the controller to a partial view (a header). The problem is that when I access a view other than the one I render in the controller, it breaks. How can I pass information to one view and make it work in all of them.

    const indexController = (req, res) => {
      let emailSession;
      if(req.session.userLogged == undefined){
          emailSession = "";
      } else {
          emailSession = req.session.userLogged.email
      }

      db.Users.findOne({
          where: {email: emailSession}
      }).then((data) => {
        res.render('index', {data}) //I want here to send the same variable to all of my views that has the same header, not just the index view
      )
    }
  <nav>
    <% if(data.info == "something") {%>
      <a href="">Dashboard</a>
    <% } %>
  </nav>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda