Opened 18 years ago

Closed 18 years ago

Last modified 17 years ago

#4474 closed (wontfix)

Add 'else' support for 'ifchanged'

Reported by: Brad McGonigle <brad@…> Owned by: Adrian Holovaty
Component: Template system Version: 0.96
Severity: Keywords: ifchanged, else
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It seems that the 'ifchanged' tag does not accept the 'else' condition as a typical 'if' tag should. I believe it should accept this but does not:

{% for date in days %}
   {% ifchanged date.date %}
      {{ date.date }}
         {% else %}
           {{ date.date2 }}
   {% endifchanged %}
{% endfor %}

Change History (3)

comment:1 by Chris Beaven, 18 years ago

Triage Stage: UnreviewedDesign decision needed

In IRC we were struggling to come up with a simple use-case for this, so perhaps it's YAGNI.

comment:2 by James Bennett, 18 years ago

Resolution: wontfix
Status: newclosed

Yeah, I can't think of any place where this would actually be necessary -- this feels like a misunderstanding of what the ifchanged tag is for.

comment:3 by chakradeo@…, 17 years ago

I think this can be useful. I was looking for this functionality. I am using django templates for venus (a python feed aggregator) and I have a use-case where this can be useful.

Items are sorted by modification date and consecutive items in the same channel (i.e. feed) are grouped in a single heading. The code looks like this:

{% for item in Items %}
{% ifchanged item.channel_id %}
<a href="{{ item.channel_link }}">{{ item.channel_name }}</a> 
{% endifchanged %}
<a name="news-{{ forloop.counter }}">&#160;</a>
  <a href="{{item.link}}"> {{ item.title }} </a> 
{{ item.content }}
{% endfor %}

The anchor link (The "a name" above) needs to be before the header for the first item in the channel group, but just before the item for subsequent items. This is where the else in ifchanged will help. Infact, I am tempted to use SmileyChris's patch for my own use.

The template is in action at http://planet.chakradeo.net/
The anchor links are used for keyboard navigation using J and K keys BTW.

So I would like to have this functionality...

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