node.js 有没有办法直接在 jade 中包含 html 文件或片段?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17903267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:08:07  来源:igfitidea点击:

Is there a way to include html file or snippet directly in jade?

node.jspug

提问by jason chen

I have a set of html files, mostly static, I would like to move to my node.js/express/jade project. What's the right way to include html file or snippet directly in jade? I don't want to translate existing html file to jade?

我有一组 html 文件,大部分是静态的,我想转移到我的 node.js/express/jade 项目。在 jade 中直接包含 html 文件或片段的正确方法是什么?我不想将现有的 html 文件翻译成玉?

回答by Jonathan Lonowski

You should be able to simply includeitwithin a jade template:

您应该能够在玉模板中简单地使用include

As mentioned includecan be used to include other content such as html or css. By providing an extension, Jade will read that file in, apply any filtermatching the file's extension, and insert that content into the output.

如前所述,include可用于包含其他内容,例如 html 或 css。通过提供扩展名,Jade 将读入该文件,应用与文件扩展名匹配的任何过滤器,并将该内容插入到输出中。

html
  // ...
  body
    // ...
    //- html files have no filter and are included verbatim
    include content.html

回答by Lorem Ipsum Dolor

Use :verbatimbefore the exact html code or snippet directly in jade.

:verbatim在 jade 中直接在确切的 html 代码或片段之前使用。

doctype html
html(lang="en")
  :verbatim
    {% include head.html %}
  body
    :verbatim
    {{ content }}

  :verbatim
    {% include footer.html %}

Output

输出

<!DOCTYPE html>
<html lang="en">{% include head.html %}
  <body>{{ content }}
  </body>{% include footer.html %}
</html>

回答by Gene Bo

In my .jade file, I had to do something like this:

在我的 .jade 文件中,我必须做这样的事情:

:verbatim
   !{editorBody}

.. where editorBodyis provided via res.render() call :

.. 其中editorBody通过 res.render() 调用提供:

var editorBody = '<p>Hello</p>';

return res.render('user/user_profile', {editorBody : editorBody});