Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display data inside input value using Jade

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
            });
        });
    };
};
like image 588
Trevan Hetzel Avatar asked Jan 23 '14 06:01

Trevan Hetzel


2 Answers

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

like image 88
asym Avatar answered Oct 12 '22 22:10

asym


You can try enclosing the variable in #{} to output it:

input(type="text", name="date", value="#{viewpost.date}")

like image 41
Munim Avatar answered Oct 12 '22 23:10

Munim