Index: django/template/defaulttags.py
===================================================================
--- django/template/defaulttags.py	(revisão 7881)
+++ django/template/defaulttags.py	(cópia de trabalho)
@@ -1103,3 +1103,104 @@
     parser.delete_first_token()
     return WithNode(var, name, nodelist)
 do_with = register.tag('with', do_with)
+
+
+class SwitchNode(Node):
+    def __init__(self, var1, nodelist_true, nodelist_false):
+        self.comparison_base = Variable(var1)
+        self.nodelist_true = nodelist_true
+        self.nodelist_false = nodelist_false
+        
+    def __repr__(self):
+        return "<SwitchNode>"
+
+    def render(self, context):
+        try:
+            val1 = self.comparison_base.resolve(context)
+            context['%BASE_COMPARISON%'] =  val1
+        except VariableDoesNotExist:
+            raise TemplateSyntaxError("Could not resolve variable %r in current context" % \
+                                      self.comparison_base.var)
+        ok = False
+        for node in self.nodelist_true:
+            if isinstance(node, CaseNode):
+                if node.get_bool(context):
+                    ok = True
+        if ok:
+            return self.nodelist_true.render(context)
+        else:
+            return self.nodelist_false.render(context)
+        
+
+def do_switch(parser, token):
+    """
+    Create a context to use case-like coditional
+    template rendering.
+
+    For example::
+
+        {% switch person.name %}
+            {% case 'John Doe' %}
+                Hi! My name is John, the master!
+            {% endcase %}
+            {% case 'Mary Jane' %}
+                Hello! My name is Mary. Nice to meet you!
+            {% endcase %}            
+        {% default %}
+            Oh my God! I have no name!
+        {% endswitch %}
+    """
+    
+    bits = list(token.split_contents())
+    if len(bits) != 2:
+        raise TemplateSyntaxError, "%r takes one argument" % bits[0]
+    end_tag = 'end' + bits[0]
+    nodelist_true = parser.parse(('default', end_tag,))
+    token = parser.next_token()
+    if token.contents == 'default':
+        nodelist_false = parser.parse((end_tag,))
+        parser.delete_first_token()
+    else:
+        nodelist_false = NodeList()
+    return SwitchNode(bits[1], nodelist_true, nodelist_false)
+do_switch = register.tag('switch', do_switch)
+
+class CaseNode(Node):
+    def __init__(self, var, nodelist):
+        self.var = Variable(var)
+        self.nodelist = nodelist
+
+    def __repr__(self):
+        return "<CaseNode>"
+
+    def get_bool(self, context):
+        try:
+            val = self.var.resolve(context)
+        except VariableDoesNotExist:
+            val = None
+        if context.get("%BASE_COMPARISON%", None) == val:
+            return True
+        else:
+            return False
+        
+    def render(self, context):
+        if self.get_bool(context):
+            return self.nodelist.render(context)
+        else:
+            return NodeList().render(context)
+
+@register.tag    
+def do_case(parser, token):
+    bits = list(token.split_contents())
+    if len(bits) != 2:
+        raise TemplateSyntaxError, "%r takes one argument" % bits[0]
+    end_tag = 'end' + bits[0]
+    nodelist_true = parser.parse(('else', end_tag))
+    token = parser.next_token()
+    if token.contents == 'else':
+        nodelist_false = parser.parse((end_tag,))
+        parser.delete_first_token()
+    else:
+        nodelist_false = NodeList()
+    return CaseNode(bits[1], nodelist_true)
+do_case = register.tag('case', do_case)
Index: docs/templates.txt
===================================================================
--- docs/templates.txt	(revisão 7881)
+++ docs/templates.txt	(cópia de trabalho)
@@ -1218,6 +1218,30 @@
 The populated variable (in the example above, ``total``) is only available
 between the ``{% with %}`` and ``{% endwith %}`` tags.
 
+switch
+~~~~
+
+**New in Django development version**
+
+Stores a variable for internal comparison with a ``{% case %}`` tag.
+This is useful comparing an "expensive" sequence of instructions ``{% ifequal %}``.
+
+For example::
+
+    {% switch person.name %}
+        {% case 'John Doe' %}
+            Hi! My name is John, the master!
+        {% endcase %}
+        {% case 'Mary Jane' %}
+            Hello! My name is Mary. Nice to meet you!
+        {% endcase %}            
+    {% default %}
+        Oh my God! I have no name!
+    {% endswitch %}
+
+The tag ``case`` above SHALL be used only within  ``{% switch %}`` and ``{% endswitch %}`` tags.
+
+
 Built-in filter reference
 -------------------------
 
