使用Node.JS Jade / Pug进行编程HTML评论

时间:2018-01-11 05:46:08

标签: node.js pug

对于layout.jade,使用环境变量"变量=开发",

我想要

  body
    // Environment: process.env.Environment || "'Environment' App Setting not found"

生成为 <!-- Environment: Development -->

到目前为止,它正在生成Environment: process.env.Environment || "'Environment' App Setting not found"

我该怎么做?

1 个答案:

答案 0 :(得分:0)

借鉴this response

body
    != "<!-- Environment: " + (process.env.Environment || "'Environment' App Setting not found") + " -->

为了便于阅读,您还可以将注释与您在上一行中设置的变量连接起来。

body
    - var envComment = process.env.Environment || "'Environment' App Setting not found"
    != "<!-- Environment: " + envComment + " -->"

但是,我认为Pug通常无法访问process.env。您需要将Node.js / Express中的变量作为变量传递给它。有关传递process.env.Environment变量的信息,请参阅this page的底部。