2016-12-22 50 views
0

我用Pug(Jade)的grunt来渲染我的HTML模板。 我想在我的Pug文件中加入Jinja2语法,但是当我运行grunt来构建HTML文件时,它会失败,因为它不能识别Jinja2语法。使用Pug(Jade)和Jinja2诱惑语法

有没有人知道这个解决方案?

+0

不可能的渲染。我会建议看看这些陈述的帕格当量。 – DevNebulae

回答

2

您看了:https://github.com/matannoam/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