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
Post a Comment