Display data inside input value using Jade
19,249
Solution 1
You can try enclosing the variable in #{}
to output it:
input(type="text", name="date", value="#{viewpost.date}")
Solution 2
Pug 0.1.0 (Jade 2.x) removed support for interpolation in attributes, so this works now:
input(type="text", name="date", value=viewpost.date)
See https://github.com/pugjs/pug/issues/2305
Author by
Trevan Hetzel
Updated on July 15, 2022Comments
-
Trevan Hetzel almost 2 years
I'm fairly new to Jade and am wanting to display some outputted data as the
value
value of a textinput
. Like this:input(type="text", name="date", value="THISRIGHTHURR")
But only the value needs to be
viewpost.date
. I've tried multiple ways and none seem to work:input(type="text", name="date", value=viewpost.date) // doesn't work input(type="text", name="date", value=.=viewpost.date) // doesn't work input(type="text", name="date", value=".=viewpost.date") // doesn't work
I of course can get it to work outside of an
input
by doing something likeeach post, i in viewpost h1.=post.date
Am I supposed to loop through in the
input
somehow too? This is the JS (using Node and Express) that's outputting myviewpost
variable.// render show post view exports.viewpost = function(db) { return function(req, res) { var id = req.params.id; collection.find({ "_id": new BSON.ObjectID(id) }, function (err, data) { res.render("viewpost", { "viewpost" : data }); }); }; };
-
Adam F over 9 yearsDon't forget it's in a string!
-
SoManyGoblins almost 8 yearsThis is outdated for Pug, view asym's answer below.