Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix join() filter with d='val' syntax to be parity with Python Jinja2 #594

Open
tjsmith-meta opened this issue Oct 7, 2024 · 1 comment
Labels
jinja-compat Jinja2 compatibility issues

Comments

@tjsmith-meta
Copy link

Description / Reproduction steps

The following template behaves differently with MiniJinja 2.3.1 vs Python Jinja2 2.11.3.

{{ ('hello', 'world') | join(d=' ') }}

MiniJinja output: hello{"d": " "}world
Python Jinja2 output: hello world

If MiniJinja intends not to support this syntax, I would expect that it might make sense for it to fail / return error instead of producing an output not consistent with Python Jinja2.

There's an example in the Python Jinja2 documentation that seems to suggest this syntax is part of the spec.
https://jinja.palletsprojects.com/en/2.11.x/templates/#join

{{ users|join(', ', attribute='username') }}

In the example, the attribute argument to join uses that sort of syntax, so it seems to suggest that the syntax should work for d as well.

@mitsuhiko
Copy link
Owner

Filters do not have perfect parity. The attribute part definitely makes sense supporting, the d part is a bit weird. A workaround for you today is the following:

{{ users|map(attribute='username')|join(', ') }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jinja-compat Jinja2 compatibility issues
Projects
None yet
Development

No branches or pull requests

2 participants