0

im trying to render a view with content from a database, my database contains html formated content and i want to keep this formatting, but when I try to render the content i get it as strings and not html, is there anyway i can parse this content and keep the formatting?

I don't want the tags to be displayed at the site.

view contact.jade

div.shareimg(style='background-image:#{document.Img}')
div#shareContent
h2.shareTag #{document.insightheader}
p.shareTag #{document.description}
b#TLDT.shareTag #{document.TLDR}
p.shareTag #{document.MoreInfo}

node

app.get('/share/:id', function(req, res) {
    var db = req.db_login;
    console.log(req.params.id)
    db.collection('insights').findById(req.params.id, function(error, document) {
        console.log(document)
        if (error || !document) {
            res.render('error', {});
        } else {
            res.render('contact', { document : document });
        }
    })
});

console.log

{
    _id: 544cf40e9f697dc430ccd2dd,
    Img: 'url(http://localhost:3000/images/previewImg.svg)',
    insightheader: '<p>dsada</p>',
    description: '<p>dsa</p><p>dsa</p><p>das</p><p>dasdd</p>',
    TLDR: '<strong>TLDR;dasdas</strong>',
    MoreInfo: '<p>dsadsa</p>',
    date: '\'1414329358033\''
}

result

enter image description here

1 Answer 1

2

With Jade you can do unescaped interpolation by using !{var} instead of #{var}.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.