NodeJS - Pug - Add variable from database in input value
Asked Answered
E

2

8

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:

Screenshot

Can someone tell me how to do this?

Estep answered 22/4, 2018 at 8:43 Comment(0)
E
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)
Electrode answered 22/4, 2018 at 9:30 Comment(0)
H
0

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

Houdini answered 27/7, 2021 at 5:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.