How to get the value on url in pug

不打扰是莪最后的温柔 提交于 2020-01-04 02:09:27

问题


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


回答1:


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)


来源:https://stackoverflow.com/questions/42280831/how-to-get-the-value-on-url-in-pug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!