Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 710
trungducng Avatar asked Feb 16 '17 17:02

trungducng


1 Answers

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)
like image 114
dNitro Avatar answered Nov 07 '22 04:11

dNitro