javascript - HTML is not rendering - Express -


i'm making simple blog app site , fetching posts array. when try use html tags in posts i'm seeing not rendering, rest of page ok.

posts:

{"post_id":1,   "post_title":"title",   "post_body":"this test text. <b> i'm testing html.</b> "} .... 

output in page :

this test text. <b> i'm testing html.</b> 

server-side:

var hbs = require('hbs');

// view engine setup app.set('view engine', 'html'); app.engine('html', hbs.__express);  app.get('/post/:id', function(req, res) {     res.render('post_theme',     {post, title etc...});     }); 

html:

<!doctype html> <html> <head>   <meta charset="utf-8" />   <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1" />   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">   <title>page</title>   <!-- font css -->   <link href='http://fonts.googleapis.com/css?family=open+sans:300,400' rel='stylesheet' type='text/css'>   <link rel="stylesheet" type="text/css" href="/lib/semantic/build/packaged/css/semantic.css">   <link rel="stylesheet" type="text/css" href="/stylesheets/style.css">   <!-- js -->   <script src="/javascripts/jquery.js"></script>   <script src="/lib/semantic/build/packaged/javascript/semantic.js"></script>   </head> <body id="home">  <div class="ui menu" > .... </div>          <h3 class="ui header">{{title}}</h3>         <p>{{body}}</p>  </body>   </html> 

why html not rendering?

(actually i'm not sure express question, i'm new web development.)


solution:

based on andrew counts answer used 3 brackets , problem solved. {{{...}}}

in handlebars templates, html codes escaped variables automatically, in order ensure values stored not able break page code flow. if sure want output html stored in variable, , not break page, can instruct handlebars not escape html, either using triple braces {{{ }}}, or storing value type 'handlebars.safestring`.

http://handlebarsjs.com/


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -