Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#4474 closed (wontfix)

Add 'else' support for 'ifchanged'

Reported by: Brad McGonigle <brad@…> Owned by: adrian
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: UI/UX:

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 Changed 8 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

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

comment:2 Changed 8 years ago by ubernostrum

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

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 Changed 8 years ago by chakradeo@…

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