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

204
Visualizações
passing dynamic url into html/pug

I have social buttons for sharing the current page on all my web application pages, the URL attribute is as follows data-url="https://www.myPage.com/whateverComes". However, I am looking for a way to have this URL dynamically from the location.href. Is there a way to achieve this without having to use javascript? maybe just plain HTML or inline javascript.

I am using pug as templating engine, -window.location.href or #{window.location.href} didn't work. Any ideas please ? thanks.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

window.location.href is a client side JavarScript variable, pug has no access to it.

Assuming you're using Node.js with express you can do something like this

app.get("/posts/:post", (req, res) => {

    res.render("page", {
        currentURL: `${req.protocol}://${req.get("host")}${req.originalUrl}`
    });
});

then in your pug template interpolate the variable:

a(data-url=currentURL)= Link
about 4 years ago · Santiago Trujillo Relatório
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