node.js - 如何在jade模板中使用HTML语法

标签 node.js pug

我想专注于学习如何在 Node 中构建东西,而不必摆弄 Jade 语法。我想知道是否可以将本地 html 语法与其循环语法等混合在 jade 模板中。如果可以,如何混合。如果没有,是否有 Node 模板引擎允许这样做。

谢谢。

最佳答案

为了确保您可以混合纯 HTML 和 Jade 代码,只需使用 Piped Text .
例如:

| <a href="#">Plain HTML</a>

这里是 Jade Online Demo 的示例(实际上很高兴尝试和测试某些东西!):

doctype html
html(lang="en")
  head
    title= pageTitle
    script(type='text/javascript').
      if (foo) {
         bar(1 + 5)
      }
  body
    h1 Jade - node template engine
    #container.col
      if youAreUsingJade
        p You are amazing
      else
        p Get on it!
      p.
        Jade is a terse and simple
        templating language with a
        strong focus on performance
        and powerful features.
    | <a href="#">Plain HTML</a>

使用此测试数据:

{
  pageTitle: 'Jade Demo',
  youAreUsingJade: true
}

生成此代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Jade Demo</title>
    <script type="text/javascript">
      if (foo) {
         bar(1 + 5)
      }
    </script>
  </head>
  <body>
    <h1>Jade - node template engine</h1>
    <div id="container" class="col">
      <p>You are amazing</p>
      <p>
        Jade is a terse and simple
        templating language with a
        strong focus on performance
        and powerful features.
      </p>
    </div><a href="#">Plain HTML</a>
  </body>
</html>

关于node.js - 如何在jade模板中使用HTML语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22661034/

相关文章:

javascript - nodejs模块中的全局对象是什么?

javascript - 使用 Express 提供静态文件

node.js - 如何使用原生 Jade 构造在 Hexo 中循环帖子

node.js - 通过node.js渲染缩略图

javascript - 在 Jade 和 Javascript 之间共享布局信息

html - pug Pretty 选项 - HTML 输出中 'a' 标记后的新行

node.js - 将 Favicon 添加到 Hexo 博客

javascript - 使用 Node.js 和 MongoDB 进行实时搜索

javascript - 如何从 Node js 中的一列中获取所有值

javascript - 当使用node js存在同名文件时如何处理文件上传