I am trying to rewrite some code that was written in jade
. I need to use express-handlebars
or something else that does not entirely alter the structure of html file. My question is: how to pass parameters in the new version, for example, the following one which is user
?
The old working version using jade
:
app.js
var router = require('express').Router();
router.get('/', function(req, res) {
res.render('index', {user: req.user});
});
index.jade
block content
if (user)
p You are currently logged in as #{user.username}
else
p You are currently not logged in. Please login or register...
The new version using handlebars
:
index.handlebars
<div class="content"></div>
So what should I write in the new index.handlebars
file and/or what to change in app.js
in order to display the user.username
correctly? I am quite new to this so I appreciate anything that helps.
#Updates#
index.handlebars
<a href="/login">Log In</a>
app.js
var router = require('express').Router();
router.get('/login', function(req, res) {
res.render('login', {user: req.user});
});
This <a>
link worked in previous index.jade
file which was written as
a(href="/login") Log In
Why it is not working in the new index.handlebars
file? (More specifically, the url changed to localhost:123/login
but the content does not change. No error in console.)