How to inject a value inside a string in pug

1.6k Views Asked by At

Hello guys I am trying to inject a value inside a pug html attribute. I can not seem to find any documentation on how to do this. Here's my code

input(type='hidden', name='country', value='#{val.snippet.id.videoId}')

as you can imagine val.snippet.id.videoId is just a javascript variable I am passing from my server side. So I want to set the value attribute to that variable. Would really appreciate if someone points me to the right direction.

2

There are 2 best solutions below

0
On BEST ANSWER

Wouldn't something like this work?

input(type='hidden', name='country', value=val.snippet.id.videoId)

As far as I remember you don't need to interpolate variables in attributes, just use them after =.

0
On

There's no need to interpolate (in attributes) since Pug 0.1.0 (Jade 2.x) as well as I know.

So, your solution is just:

input(type='hidden', name='country', value=val.snippet.id.videoId)