【问题标题】:Using Pug (Jade) with Jinja2 tempting syntax使用带有 Jinja2 诱人语法的 Pug (Jade)
【发布时间】:2016-12-22 08:05:45
【问题描述】:

我使用 grunt 和 Pug (Jade) 来呈现我的 HTML 模板。 我想在我的 Pug 文件中加入 Jinja2 语法,但是当我运行 grunt 来构建 HTML 文件时它失败了,因为它无法识别 Jinja2 语法。

有人知道解决办法吗?

【问题讨论】:

  • 不可能。我建议查看这些陈述的哈巴狗等价物。

标签: python gruntjs pug jinja2


【解决方案1】:

你看过:https://github.com/kakulukia/pypugjs 吗?

似乎支持 Jinja2:

jinja_env = Environment(extensions=['pypugjs.ext.jinja.PyPugJSExtension'])

下面的哈巴狗(玉)代码示例

!!! 5
html(lang="en")
  head
    title= pageTitle
    script(type='text/javascript').
      if (foo) {
         bar()
      }
  body
    h1.title PugJS - node template engine
    #container
      if youAreUsingPugJS
        p You are amazing
      else
        p Get on it!

转换为:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>{{pageTitle}}</title>
    <script type='text/javascript'>
      if (foo) {
         bar()
      }
    </script>
  </head>
  <body>
    <h1 class="title">PugJS - node template engine</h1>
    <div id="container">
      {%if youAreUsingPugJS%}
        <p>You are amazing</p>
      {%else%}
        <p>Get on it!</p>
      {%endif%}
    </div>
  </body>
</html>

您可以使用以下实用程序命令来执行此操作:

pypugjs -c jinja input.pug output.html

【讨论】:

    【解决方案2】:

    我基本上写了a whole library,这样我就可以做同样的事情, 特别是作为Pyramid中的渲染器

    【讨论】:

      猜你喜欢
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-16
      • 2016-12-01
      相关资源
      最近更新 更多