Shadid
Shadid

Reputation: 4252

How to inject a value inside a string in pug

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.

Upvotes: 3

Views: 1854

Answers (2)

impregnable fiend
impregnable fiend

Reputation: 289

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)

Upvotes: 3

alvvi
alvvi

Reputation: 86

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 =.

Upvotes: 4

Related Questions