I'm fairly new to Jade and am wanting to display some outputted data as the value
value of a text input
. 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 like
each 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 my viewpost
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
});
});
};
};
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
You can try enclosing the variable in #{}
to output it:
input(type="text", name="date", value="#{viewpost.date}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With