#9456 closed (fixed)
Extend with tag to support multiple bindings
| Reported by: | eibaan | Owned by: | Łukasz Rekucki |
|---|---|---|---|
| Component: | Template system | Version: | 1.0 |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Attached is a patch that extends the with template tag in a fully backward compatible way (I hope) so that you can write
{% with expr1 as var1 and expr2 as var2 and expr3 as var3 %} ...
instead of
{% with expr1 as var1 %}
{% with expr2 as var2 %}
{% with expr3 as var3 %}
...
Attachments (2)
Change History (10)
by , 17 years ago
| Attachment: | with.patch added |
|---|
comment:1 by , 17 years ago
comment:2 by , 17 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
comment:4 by , 15 years ago
| Resolution: | duplicate |
|---|---|
| Status: | closed → reopened |
| Triage Stage: | Unreviewed → Design decision needed |
#7817 dealt with two separate feature requests here, one for {% with %} and one for {% include %}.
I'm leaving that one to deal with just {% include %} and reopening this one to track {% with %}
comment:5 by , 15 years ago
| Owner: | changed from to |
|---|---|
| Status: | reopened → new |
Ok, I'm goning to split the with part form #7817. It's diffrent from patch on this ticket, that it resolves all variables in the outer context, so you can do
{% with x as y and y as x %}{% endwith %}
to swap the variables. It's also with line how Python does assignment and how most languages handle "let" statement (which I find very similar in semantic to the with tag).
by , 15 years ago
| Attachment: | ticket9456_r13997.diff added |
|---|
Patch from #7817, but only has "with" related stuff.
comment:6 by , 15 years ago
| milestone: | → 1.3 |
|---|---|
| Triage Stage: | Design decision needed → Accepted |
Following a BDFL pronouncement, this has been accepted, using the {% with foo=x bar=y %} syntax. Related ticket: #7817.
comment:7 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
(In [14922]) Fixes #7817 and #9456.
- The include tag now has a 'with' option to include to provide extra context vairables to the included template.
- The include tag now has an 'only' option to exclude the current context when rendering the included template.
- The with tag now accepts multiple variable assignments.
- The with, include and blocktrans tags now use a new keyword argument format
for variable assignments (e.g.
{% with foo=1 bar=2 %}).
duplicate of #7817.