callum
callum

Reputation: 37819

How to have a dynamic value in an HTML comment in Jade?

I want to programatically set the content of a comment. But this doesn't work:

p Hello
// = 'Generated at ' + date

It just outputs this:

<p>Hello</p>
<!-- = 'Generated at ' + date -->

How can I output a comment with something dynamic in it? I can't see anything in the docs about this.

Upvotes: 1

Views: 326

Answers (2)

Matias Kinnunen
Matias Kinnunen

Reputation: 8540

Interpolation seems to work in block comments:

- const date = new Date()

// Generated at #{date}

//
  Generated at #{date}

Output (using Pug 2.0.4):

<!-- Generated at #{date}-->

<!--Generated at Sun Jan 24 2021 20:30:16 GMT+0200 (Eastern European Standard Time)-->

Upvotes: 0

user142162
user142162

Reputation:

Unfortunately for you in this case, Jade does not evaluate the comment's value. You can hack around this by doing:

!='<!-- Generated at ' + date + '-->'

Upvotes: 4

Related Questions