Opened 8 years ago

Closed 6 years ago

Last modified 5 years ago

#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: UI/UX:

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)

with.patch (3.4 KB) - added by eibaan 8 years ago.
ticket9456_r13997.diff (5.0 KB) - added by Łukasz Rekucki 6 years ago.
Patch from #7817, but only has "with" related stuff.

Download all attachments as: .zip

Change History (10)

Changed 8 years ago by eibaan

Attachment: with.patch added

comment:1 Changed 8 years ago by Johannes Dollinger

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

duplicate of #7817.

comment:2 Changed 8 years ago by Jacob

Resolution: duplicate
Status: newclosed

comment:3 Changed 8 years ago by Antti Kaihola

I attached eibaan's patch above with slight improvements to #7817.

comment:4 Changed 6 years ago by Chris Beaven

Resolution: duplicate
Status: closedreopened
Triage Stage: UnreviewedDesign 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 Changed 6 years ago by Łukasz Rekucki

Owner: changed from nobody to Łukasz Rekucki
Status: reopenednew

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).

Changed 6 years ago by Łukasz Rekucki

Attachment: ticket9456_r13997.diff added

Patch from #7817, but only has "with" related stuff.

comment:6 Changed 6 years ago by Russell Keith-Magee

milestone: 1.3
Triage Stage: Design decision neededAccepted

Following a BDFL pronouncement, this has been accepted, using the {% with foo=x bar=y %} syntax. Related ticket: #7817.

comment:7 Changed 6 years ago by Chris Beaven

Resolution: fixed
Status: newclosed

(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 %}).

comment:19 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top