Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda