如何在jade模板中使用HTML语法

时间:2014-03-26 12:27:50

标签: node.js pug

我想专注于学习如何在节点中构建东西,而不必使用jade语法。我想知道是否有可能在jade模板中混合原生html语法及其循环语法等。如果是这样的话。如果没有,是否有节点的模板引擎允许这样做。

谢谢。

1 个答案:

答案 0 :(得分:2)

当然,您可以混合纯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>