javascript - Node.js express and EJS passing object to template -


i'm passing object template , want display object details in html.

app.get('/', function (req, res) {     var user = req.session.passport.user;      if ( user != 'undefined' ){         res.render('pages/chat.ejs', {             user_data: user // user out of session , pass template         });     } else {         res.render('pages/chat.ejs', {             user_data: false         });     } }); 

and in pages/chat.ejs:

<% if (!user_data) { %>             <div class="buttons pull-right clearfix">                 <span data-action="chatlogin" class="pull-right bordered button_blue button">log in</span>             </div>             <% } else { %>             <div class="buttons pull-right clearfix">                 <span data-action="addchatmessage" class="pull-right bordered button_red button">send</span>                 <span class="pull-right bordered button_blue button" id="user_name_details">                     <% user_data.user_display_name %>                 </span>             </div>             <% } %> 

but there nothing in <% user_data.user_display_name %> how display object details in template?

use <%= user_data.user_display_name %>

<% %> used marking control flow.. not output data

<%= %> used output data of enclosed variable in template

<%- %> used output unescaped value of variable in template characters < , > don't eaten html parser.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -