Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS - Pug - Add variable from database in input value

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?

like image 594
Caroline Avatar asked Apr 22 '18 08:04

Caroline


1 Answers

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)
like image 179
m90 Avatar answered Oct 27 '22 01:10

m90