Reputation: 19
I want to send a variable from Express to Pug.
Therefore I found already that I have to use res.render(), but if I try this, I only get an undefined variable.
In my index.js:
app.post("/example", upload.single("photo"), (req, res) => {
{... some code}
var html = "some text";
res.render("results", {
html: html
});
and in my results.pug I try to show the text as a string:
p "#{html}"
At the moment I only get two "" on my page. But I need to show the result
Thank you for your help!!!! :)
Upvotes: 0
Views: 428
Reputation: 7802
Your issue is with how you are calling the variable in your pug template. This is the easiest way to do it:
p= html
or
p
div= html
If you really wanted to use interpolation the syntax would be:
p #{html}
I'd bet that if you View Source on your current page you will have something that looks like this:
<p>#{html}</p>
Upvotes: 1