Add 'flip' filter
@palchukovsky is already working on this.
Since Aug 26, 2019.
Assessment
This issue has not been assessed yet.
Description
According to this pull request: https://github.com/pallets/jinja/pull/906
Applies a filter with arguments flipped in reverse order.
This becomes useful with filters like map where you can't easily re-order
the arguments yourself.
Example 1:
Say you have a list of names and you want to prefix them all with "Name: "
you could do it like this:
.. sourcecode:: jinja
{{ ["Carl", "Jane"] | map("flip", "format", "Name: %s") | join(",") }}
This would give you back:
Name: Carl, Name: Jane
Example 2:
Say you have a User object like below:
.. sourcecode:: python
class User(object):
def init(self, name, surname, age):
self.name = name
self.surname = surname
self.age = age
user = User('john', 'doe', 31)
... and you want to extract a couple of attribute values from it as a list
and process that.
This is one way to do that:
.. sourcecode:: jinja
{{ ['surname', 'name']
| map("flip", "attr", user)
| map("capitalize")
| join(", ")
}}
This would give you back
Doe, John
- Dominant language
- C++
- Stars
- 600
- Forks
- 114
- PR merge metrics
- No merged PRs in 30d
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from jinja2cpp/Jinja2Cpp
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 4/5 3-5 days Newbie friendliness 65/100
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
All issues in jinja2cpp/Jinja2Cpp
Similar issues
-
component: split-view platform: windows
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
zen-browser/desktop#15616 · 1 reaction ·
Maintainers usually reply within 1 day
-
area/ysql kind/bug priority/medium status/awaiting-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
yugabyte/yugabyte-db#34415 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
WayfireWM/wayfire#3148 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
backend:DirectX
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
llvm/llvm-project#227530 ·
Maintainers usually reply within 1 day