Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I should definitely update that section. The mozilla marketplace (see fireplace[1]) actually ended up using it, and they share templates across Python and node.

It is mostly feature-compatible, but there definitely differences, and the fireplace project installs a compatibility layer. There are minor things, like `True` is `true` in nunjucks, and arrays have different methods. Also, all filters/extensions must be written both in node and Python.

You can go very far though. I'm considering adopting this compatibility layer and putting it behind a flag. It takes some work, but you can definitely do it.

[1] https://github.com/mozilla/fireplace/



Thanks for the reply, I'm actually going to give nunjucks + jinja2 a shot now.

Food for thought: jinja2.meta exposes the AST after parsing the template. Could you use this to do Angular style data binding?


What do mean exposes? Once the code is generated, the AST is gone (or so I thought). But yeah, there's some neat things we could do with massaging the AST into something more like Angular. Stop giving me ideas!


Take this:

    env = jinja2.Environment()
    ast = env.parse(...)
    vars = jinja2.meta.find_undeclared_variables(ast)
Now you've got a list of every part of the data model referenced by this template. Unfortunately this doesn't give you byte ranges for each reference, but that could be changed.

Angular propagates changes to your data model to only the parts of the DOM that depend on it, which is cool. Imagine if you could do the same against a nunjucks template. Given the above kind of dependency analysis, I don't see why not.

Maybe rendering snippets of a jinja template at runtime is problematic?

Aside: yikes on the string-based codegen here...I bet you wish you were still writing scheme ;)

https://github.com/jlongster/nunjucks/blob/master/src/compil...


Oh, yes, nunjucks features a full AST and parser like jinja2. The compiler calls `parse` and then `compiler`, so we can analyze the tree between those two stages as well. I'm thinking of hacking around on this, it is interesting!




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: