Re: [Django] #12199: Give 'firstof' tag ability to assign result to context

8 views
Skip to first unread message

Django

unread,
Mar 22, 2013, 3:20:34 PM3/22/13
to django-...@googlegroups.com
#12199: Give 'firstof' tag ability to assign result to context
--------------------------------------+------------------------------------
Reporter: tiliv | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: firstof, as, context | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by aaugustin):

* stage: Design decision needed => Accepted


Comment:

I don't know what the "capture" tag discussed 3 years ago was, but AFAIK
it didn't come into existence.

This feature can be useful and it's still quite restricted -- it isn't a
general switch statement.

--
Ticket URL: <https://code.djangoproject.com/ticket/12199#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 14, 2013, 2:51:26 PM5/14/13
to django-...@googlegroups.com
#12199: Give 'firstof' tag ability to assign result to context
--------------------------------------+------------------------------------
Reporter: tiliv | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: firstof, as, context | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by mark0978@…):

There is another instance where the AS keyword would be very useful

Trying to write a template to include something for xyz: in json, but i
can't put {% firstof %} output thru escapejs as it currently stands.

{{{
xyz: '{% firstof a b %}',
}}}

with AS, we could do:

{{{
{% firstof a b AS c %}
xyz: '{{ c|escapejs }}',
}}}

Right now to do this you end up with a logic block in the template.

{{{
{% if a %}{{ a|escapejs }}{% else %}{{ b|escapejs }}{% endif %}
}}}

which isn't horrible until you only want a or b if EITHER of them is
defined and then it looks like:

{{{
{% if a or b %}xyz: '{% if a %}{{ a|escapejs }}{% else %}{{ b|escapejs
}}{% endif %}',{% endif %}
}}}

while it could be as simple as:

{{{
{% firstof a b AS c %}{% if c %}xyz: '{{ c|escapejs }}',{% endif %}
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/12199#comment:8>

Django

unread,
Apr 13, 2015, 9:59:00 AM4/13/15
to django-...@googlegroups.com
#12199: Give 'firstof' tag ability to assign result to context
--------------------------------------+------------------------------------
Reporter: tiliv | Owner: craigls
Type: New feature | Status: assigned

Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: firstof, as, context | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by craigls):

* owner: nobody => craigls
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/12199#comment:9>

Django

unread,
Apr 14, 2015, 7:20:13 AM4/14/15
to django-...@googlegroups.com
#12199: Give 'firstof' tag ability to assign result to context
--------------------------------------+------------------------------------
Reporter: tiliv | Owner: craigls
Type: New feature | Status: closed

Component: Template system | Version: master
Severity: Normal | Resolution: fixed

Keywords: firstof, as, context | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"75bc5bc634e90d5ccd2d7fc324df878dc5d4ce5d" 75bc5bc6]:
{{{
#!CommitTicketReference repository=""
revision="75bc5bc634e90d5ccd2d7fc324df878dc5d4ce5d"
Fixed #12199 -- Added the ability to use "as" with the firstof template
tag.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/12199#comment:10>

Reply all
Reply to author
Forward
0 new messages