最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NodeJS - Pug - Add variable from database in input value - Stack Overflow

programmeradmin3浏览0评论

I'm trying to show the value from #{product.name} in a textfield. This is my code, but it doesn't work

label Name
input(type='text', placeholder='Name', name='name' value='#{product.name}')

This is my result:

Can someone tell me how to do this?

I'm trying to show the value from #{product.name} in a textfield. This is my code, but it doesn't work

label Name
input(type='text', placeholder='Name', name='name' value='#{product.name}')

This is my result:

Can someone tell me how to do this?

Share Improve this question edited Apr 22, 2018 at 9:33 m90 11.8k14 gold badges67 silver badges119 bronze badges asked Apr 22, 2018 at 8:43 CarolineCaroline 931 silver badge7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13

Assuming that you are using a newer version of pug, string interpolation in attributes has been removed from the language in favor of ES6-template-strings.

This means you are in theory supposed to use syntax like this now:

input(type='text', placeholder='Name', name='name' value=`${product.name}`)

That being said, your example does not require using interpolation at all, and you could simply be passing the variable's value:

input(type='text', placeholder='Name', name='name', value=product.name)

input(type="text", name="hidden", value=product.name, checked="")

发布评论

评论列表(0)

  1. 暂无评论