trungducng
trungducng

Reputation: 397

How to get the value on url in pug

I have an url like this: http://localhost/editblog/58a5da1df3ec9614fc9893d3

and code in pug like this:

 input.form-control(type='hidden', name='id', value='')

The question is how to get the value on the url and pass it to value=''

I've known about req.params.id but it is not what could solve my issue

Upvotes: 8

Views: 11977

Answers (1)

dNitro
dNitro

Reputation: 5345

When you render your pug template you could send any variable as res.locals property so it will send to template:

app.get('/editblog/:id', function(req, res) {
  res.render('editblog', { title: 'edit blog', id: req.params.id });
});

And now you have access to id whithin your template:

editblog.pug:

input.form-control(type='hidden', name='id', value=id)

Upvotes: 6

Related Questions