I cannot double interpolate like this. Is there a way to double interpolate?
p #{selected} #{val.#{selectedraw}}
val has an attribute dynamically selected when the user presses a select on a form.
so I need to double interpolate. Is there a way?
I cannot double interpolate like this. Is there a way to double interpolate?
p #{selected} #{val.#{selectedraw}}
val has an attribute dynamically selected when the user presses a select on a form.
so I need to double interpolate. Is there a way?
From Interpolation in Pug docs:
The code in between
#{and}is evaluated, escaped, and the result buffered into the output of the template being rendered.This can be any valid Javascript expression, so you can do whatever feels good.
So, you can use the regular bracket notation as you would in JavaScript:
- const selected = 'foo'
- const selectedraw = 'bar'
- const val = { bar: 'ham', qux: 'spam' }
p #{selected} #{val[selectedraw]}
Output:
<p>foo ham</p>