Index: django/template/defaulttags.py =================================================================== --- django/template/defaulttags.py (revision 3768) +++ django/template/defaulttags.py (working copy) @@ -120,15 +120,22 @@ return nodelist.render(context) class IfChangedNode(Node): - def __init__(self, nodelist): + def __init__(self, nodelist, var1=None): self.nodelist = nodelist self._last_seen = None + self._var1 = var1 def render(self, context): - content = self.nodelist.render(context) - if content != self._last_seen: + try: + if self._var1==None: + compare_to = self.nodelist.render(context) + else: + compare_to = resolve_variable(self._var1, context) + except VariableDoesNotExist: + compare_to = None + if compare_to != self._last_seen: firstloop = (self._last_seen == None) - self._last_seen = content + self._last_seen = compare_to context.push() context['ifchanged'] = {'firstloop': firstloop} content = self.nodelist.render(context) @@ -626,23 +633,27 @@ """ Check if a value has changed from the last iteration of a loop. - The 'ifchanged' block tag is used within a loop. It checks its own rendered - contents against its previous state and only displays its content if the - value has changed:: + The 'ifchanged' block tag is used within a loop. It has two possible uses. + 1) It checks its own rendered contents against its previous state and + only displays its content if the value has changed. + 2) It checks if the given variable has changed. ::