0 votes
1 view
in Python by (11.8k points)
I utilize grunt with Pug (Jade) to deliver my HTML layouts. I need to consolidate Jinja2 syntax in my Pug records however when I run grunt to assemble the HTML documents it comes up fails since it doesn't perceive the Jinja2 language structure.

Does anybody know an answer to this?

1 Answer

0 votes
by (24.6k points)

Seems like it supports jinja2:

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

Look at the below pug (jade) code example:

!!! 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!

Converts into

<!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>

You can also utilize the utility command:

pypugjs -c jinja input.pug output.html

Wanna become a Python expert? Come and join the python certification course and get certified.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...