#12199: Give 'firstof' tag ability to assign result to context
----------------------------------+-----------------------------------------
 Reporter:  tiliv                 |       Owner:  nobody    
   Status:  new                   |   Milestone:  1.2       
Component:  Template system       |     Version:  SVN       
 Keywords:  firstof, as, context  |       Stage:  Unreviewed
Has_patch:  1                     |  
----------------------------------+-----------------------------------------
 When you need to access fields on objects in a {{{ {% firstof %} }}}
 fashion, semantically 'optional' fields can cause issues:

 {{{
     Today the teacher is {% firstof substitute.name teacher.name %},
     and drives a {% firstof substitute.car teacher.car %}
 }}}

 If {{{ substitute }}} doesn't have a value for {{{ car }}}, then it will
 fall back to {{{ teacher.car }}}.

 The real issue is that {{{ {% firstof %} }}} cannot preserve its value for
 later multiple inspections.  If the {{{ {% firstof %} }}} tag could assign
 its result to a context variable, it would solve this problem:

 {{{
     {% firstof substitute teacher as teacher_for_today %}
     Today the teacher is {{ teacher_for_today }}
     {% if teacher_for_today.car %}
         and drives a {{ teacher_for_today.car }}
     {% endif %}
 }}}


 I am unsure that this is possible to achieve without the {{{ as }}}
 syntax.  One would have to code a template tag or filter for the sole
 purpose of duplicating the exact functionality that I propose be added to
 {{{ {% firstof %} }}}.

 Attached patch for functionality and documentation on the subject.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12199>
Django <http://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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to