Django

Code

Ticket #2800 (closed: fixed)

Opened 4 years ago

Last modified 3 years ago

[patch] Make ifchanged tag accept a parameter

Reported by: wolfram@kriesing.de Assigned to: adrian
Milestone: Component: Template system
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

enhanced-ifchanged.patch (2.5 kB) - added by anonymous on 09/23/06 10:37:03.
ifchanged-tests.patch (1.4 kB) - added by anonymous on 09/25/06 04:38:26.
ifchanged-multi-parameters.patch (6.2 kB) - added by anonymous on 10/24/06 05:30:18.

Change History

09/23/06 10:37:03 changed by anonymous

  • attachment enhanced-ifchanged.patch added.

09/23/06 10:41:00 changed 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.

09/25/06 04:38:26 changed by anonymous

  • attachment ifchanged-tests.patch added.

09/27/06 22:56:37 changed by anonymous

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

10/24/06 05:29:39 changed by wolfram.kriesing@gmail.com

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

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

Examples, doc and tests included.

10/24/06 05:30:18 changed by anonymous

  • attachment ifchanged-multi-parameters.patch added.

11/06/06 23:36:51 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(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.

04/02/07 00:51:36 changed by anonymous

04/02/07 00:52:28 changed by anonymous


Add/Change #2800 ([patch] Make ifchanged tag accept a parameter)




Change Properties
Action