Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#2800 closed enhancement (fixed)

[patch] Make ifchanged tag accept a parameter

Reported by: wolfram@… Owned by: adrian
Component: Template system Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The patch allows to pass a parameter to ifchanged, which is then evaluated and checked if it has changed, instead of the tag’s content. If it has changed the content is being printed, as usual. I.e. you can do

{% ifchanged variable %}print if variable's value has changed{% ifchanged %}

To know more about the details, read here.

Attachments (3)

enhanced-ifchanged.patch (2.5 KB) - added by anonymous 9 years ago.
ifchanged-tests.patch (1.4 KB) - added by anonymous 9 years ago.
ifchanged-multi-parameters.patch (6.2 KB) - added by anonymous 9 years ago.

Download all attachments as: .zip

Change History (9)

Changed 9 years ago by anonymous

comment:1 Changed 9 years ago by Wolfram Kriesing

A little more explaination may be. In my case I had nested for loops and wanted to check if the outer had changed and modify something inside the inner loop.
That was impossible using ifchanged without telling what to look for if it had changed, so I enhanced ifchanged's syntax.
I hope you find it useful too.
Having ifchanged accept a parameter would be phantastic. Like so:

{% for country in countries %}
    {% for city in country.cities %}
        <div class="city{% ifchanged country %}Alternate{% endifchanged %}">
            {{ city.name }}
        </div>
    {% endfor %}
{% endfor %}

The ifchanged tag should be able to check if a certain variable has changed if given, otherwise work as usual.

Changed 9 years ago by anonymous

comment:2 Changed 9 years ago by anonymous

  • Summary changed from Make ifchanged tag accept a parameter to [patch] Make ifchanged tag accept a parameter

comment:3 Changed 9 years ago by wolfram.kriesing@…

The following updated patch allows for multiple parameters, such as:

{% ifchanged date.hour,date.date %}

Examples, doc and tests included.

Changed 9 years ago by anonymous

comment:4 Changed 9 years ago by jacob

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

(In [4050]) Fixed #2800: the ifchanged tag now can optionally take paramaters to be checked for changing (instead of always using the content). Thanks, Wolfram Kriesing.

comment:5 Changed 8 years ago by anonymous

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