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

202
Views
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 answers
Answer question

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 Report
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!