Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert Image using Jade and NodeJS

How can I use an object that I've passed through to jade within an image, I'm also using mongodb to hold the data.

Currently this is my code:

db.collection('blogposts', function(err, collection) {
    if (err) throw err;
    collection.find().toArray(function(err, docs) {
        if (err) throw err;
        res.render('table', { title: 'Blog Posts', tab: "list" , blogposts: docs });
    });
});

So I have the nodejs passing through a mongodb collection through to jade, Then within Jade I have:

div.span9
    table.table.table-bordered.table-striped.noborder

        each row in blogposts
            tr
                td
                    div.blogtitle #{row.Title}
                    br
                    div.blogheading #{row.Heading}
                    br
                    div.namedate #{row.Namedate}
                    br
                    div.imagetable
                        img(src='')
                    br
                    div.blogposts #{row.Posts}
                    br
                    div.blogtags Tags: #{row.Tags}

And what I'm trying to do is use #{row.Image} within the actual img(src='') as the source.

It appears that I must use some other syntax or something to use it within the source as just putting it in doesn't work.

like image 391
brent Avatar asked Aug 04 '13 04:08

brent


1 Answers

Just do img(src= "http://" + row.Image)

Jade will treat the src attribute value as a javascript expression, evaluate it and render the HTML as you would expect.

like image 137
Peter Lyons Avatar answered Nov 05 '22 02:11

Peter Lyons