#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to