Where does Rinja draw the line with regard to maintaining Jinja2 template compatibility #280
cipriancraciun
started this conversation in
General
Replies: 1 comment 1 reply
-
I think
Sounds pretty neat, please open an issue so it can be added. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I know that Rinja doesn't explicitly state anything about Jinja2 compatibility (with regard to template syntax and semantics), but in a few issues I've opened, the Jinja2 compatibility was an important factor in judging if the Rinja implementation has a bug or it just "works as expected".
I want to highlight that I don't want to dispute the judgement of the issues in question, I just wanted to ask this broader question to have at least some guidance on the subject.
(Personally I would actually prefer Jinja2 compatibility, given it's larger ecosystem, and the fact that one could prototype with Jinja2 in Python and then use Rinja in Rust for production. But this is besides the point for this question. And it's perhaps less feasible for non-trivial contexts due to the Rust / Python mismatch.)
Here are a few examples where Jinja2 works in one way, meanwhile Rinja differs (or vice-versa):
{% extends "base.txt" %}
, then anything encountered before the statement is actually printed in the output, meanwhile in Rinja (and Askama) it is completely ignored; (in fact Jinja2 describes where such a feature would be useful: https://jinja.palletsprojects.com/en/stable/tricks/#null-default-fallback));{%- extends "base.txt" -%}
, meanwhile Rinja (and Askama) fail to compile; (I believe this should be allowed, as it's a benign usage of{%-
, without any semantic change;){% block some_block %}{% endblock %}
and it would be rendered a second time, meanwhile Jinja2 disallows this syntax and indicates the usage of{{ self.some_block() }}
;{% call macro() %}<some-html>{% endcall %}
and the macro can then{{ caller() }}
to include it, as opposed to Rinja (and Askama) that don't provide such a feature; (this would be very useful when designing HTML widgets as macros!)Perhaps there are more examples like this, mostly corner-cases, but I've discovered them while experimenting with other issues.
Beta Was this translation helpful? Give feedback.
All reactions