Given a jade template and a dictionary, how can I use the dictionary to populate the jade template? For example,
>>> data = {
... 'name': "World",
... 'ages': [10, 20, 30]
... }
>>> template = """
... html
... body
... h1 "Hello, #{name}!"
... each age in ages
... h3 "Age: #{age}"
... """
>>> print interpolate(template, data)
<html>
<body>
<h1>Hello, World!</h1>
<h3>Age: 10</h2>
<h3>Age: 20</h2>
<h3>Age: 30</h2>
</body>
</html>
I've been looking at pyjade
, but I can't figure out where a function like interpolate
is defined. How do I write interpolate
?
pyjade
doesn't give you the option to directly interpolate jade and python objects; rather, it allows conversion of jade to a format friendly to another template engine, such as Jinja2. This template engine can then do the interpolation for you. For example,