Opened 7 years ago

Closed 4 years ago

Last modified 4 years ago

#9456 closed (fixed)

Extend with tag to support multiple bindings

Reported by: eibaan Owned by: lrekucki
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 7 years ago.
ticket9456_r13997.diff (5.0 KB) - added by lrekucki 5 years ago.
Patch from #7817, but only has "with" related stuff.

Download all attachments as: .zip

Change History (10)

Changed 7 years ago by eibaan

comment:1 Changed 7 years ago by emulbreh

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

duplicate of #7817.

comment:2 Changed 6 years ago by jacob

  • Resolution set to duplicate
  • Status changed from new to closed

comment:3 Changed 6 years ago by akaihola

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

comment:4 Changed 5 years ago by SmileyChris

  • Resolution duplicate deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to 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 Changed 5 years ago by lrekucki

  • Owner changed from nobody to lrekucki
  • Status changed from reopened to 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).

Changed 5 years ago by lrekucki

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

comment:6 Changed 4 years ago by russellm

  • milestone set to 1.3
  • Triage Stage changed from Design decision needed to Accepted

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

comment:7 Changed 4 years ago by SmileyChris

  • Resolution set to fixed
  • Status changed from new to 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 %}).

comment:19 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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