In the following, myVar
contains the string "Today, it's the ${date}".
Furthermore, there is an variable with the name date
that contains "1st of October". I expect the following pug syntax to replace the literal ${date}
with the date
variable content.
span!= myVar
Unfortunately, the example results in
<span>Today, it's the ${date}</span>
Expected result:
<span>Today, it's the 1st of October.</span>
Best regards, Benedikt
Yes, exactly as @omgninjas pointed out, it is called interpolation and preceded by # in Pug.
However you can't always use it (eg. inside a string). Here are some examples:
sensor
is a variable passed by the controller to the view.
<div id=#{sensor} style="width:90%;height:250px;"></div>
img(src=`/images/${sensor}.png`, style="width:20%")
body(onload="initTemp('"+ sensor +"')")
Here is the official documentation for Pug interpolation: https://pugjs.org/language/interpolation.html
Hope this helps. Corrections and suggestions always welcome!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With