diff --git a/django/template/__init__.py b/django/template/__init__.py
index 4c386be..881e16a 100644
--- a/django/template/__init__.py
+++ b/django/template/__init__.py
@@ -275,14 +275,14 @@ class Parser(object):
                 var_node = self.create_variable_node(filter_expression)
                 self.extend_nodelist(nodelist, var_node,token)
             elif token.token_type == TOKEN_BLOCK:
-                if token.contents in parse_until:
-                    # put token back on token list so calling code knows why it terminated
-                    self.prepend_token(token)
-                    return nodelist
                 try:
                     command = token.contents.split()[0]
                 except IndexError:
                     self.empty_block_tag(token)
+                if command in parse_until:
+                    # put token back on token list so calling code knows why it terminated
+                    self.prepend_token(token)
+                    return nodelist
                 # execute callback function for this tag and append resulting node
                 self.enter_command(command, token)
                 try:
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 2ccfc6a..28b3385 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -231,32 +231,39 @@ class IfEqualNode(Node):
         return self.nodelist_false.render(context)
 
 class IfNode(Node):
-    def __init__(self, var, nodelist_true, nodelist_false=None):
-        self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
-        self.var = var
+    def __init__(self, condition_nodelists, else_nodelist):
+        self.condition_nodelists = condition_nodelists
+        self.else_nodelist = else_nodelist
 
     def __repr__(self):
         return "<If node>"
 
     def __iter__(self):
-        for node in self.nodelist_true:
-            yield node
-        for node in self.nodelist_false:
+        for condition, nodelist in self.condition_nodelists:
+            for node in nodelist:
+                yield node
+
+        for node in else_nodelist:
             yield node
 
     def get_nodes_by_type(self, nodetype):
         nodes = []
         if isinstance(self, nodetype):
             nodes.append(self)
-        nodes.extend(self.nodelist_true.get_nodes_by_type(nodetype))
-        nodes.extend(self.nodelist_false.get_nodes_by_type(nodetype))
+
+        for condition, nodelist in self.condition_nodelists:
+            nodes.extend(nodelist.get_nodes_by_type(nodetype))
+
+        nodes.extend(self.else_nodelist.get_nodes_by_type(nodetype))
+
         return nodes
 
     def render(self, context):
-        if self.var.eval(context):
-            return self.nodelist_true.render(context)
-        else:
-            return self.nodelist_false.render(context)
+        for condition, nodelist in self.condition_nodelists:
+            if condition.eval(context):
+                return nodelist.render(context)
+
+        return self.else_nodelist.render(context)
 
 class RegroupNode(Node):
     def __init__(self, target, expression, var_name):
@@ -788,6 +795,18 @@ def do_if(parser, token):
     As you can see, the ``if`` tag can take an option ``{% else %}`` clause
     that will be displayed if the test fails.
 
+    If you have multiple conditions to check against, you may wish to use
+    the ``elif`` tag::
+    
+        {% if athlete_list %}
+            Number of athletes: {{ athlete_list|length }}
+        {% elif athletes_in_lockerroom %}
+            There are some athletes queued in the locker room, but they
+            should be out soon!
+        {% else %}
+            No athletes.
+        {% endif %}
+
     ``if`` tags may use ``or``, ``and`` or ``not`` to test a number of
     variables or to negate a given variable::
 
@@ -824,16 +843,37 @@ def do_if(parser, token):
 
     Operator precedence follows Python.
     """
-    bits = token.split_contents()[1:]
-    var = TemplateIfParser(parser, bits).parse()
-    nodelist_true = parser.parse(('else', 'endif'))
-    token = parser.next_token()
-    if token.contents == 'else':
-        nodelist_false = parser.parse(('endif',))
-        parser.delete_first_token()
-    else:
-        nodelist_false = NodeList()
-    return IfNode(var, nodelist_true, nodelist_false)
+    # The condition nodelist is constructed of:
+    # [(<if_var>, <nodelist>),
+    #   <if_var>, <nodelist>])]
+    #
+    # So as soon as one of these conditions evaluates to True, the
+    # accompanying nodelist is evaluated.
+    condition_nodelists = []
+    else_nodelist = None
+    all_parsed = False
+
+    while not all_parsed:
+        bits = token.split_contents()[1:]
+        var = TemplateIfParser(parser, bits).parse()
+        nodelist = parser.parse(('elif', 'else', 'endif'))
+        condition_nodelists.append((var, nodelist))
+
+        token = parser.next_token()
+        command = token.contents.split()[0]
+        if command == 'elif':
+            pass
+        elif command == 'else':
+            else_nodelist = parser.parse(('endif',))
+            parser.delete_first_token()
+            all_parsed = True
+        elif command == 'endif':
+            all_parsed = True
+
+    if not else_nodelist:
+        else_nodelist = NodeList()
+
+    return IfNode(condition_nodelists, else_nodelist)
 do_if = register.tag("if", do_if)
 
 #@register.tag
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index 51ef03c..16f1820 100644
--- a/docs/ref/templates/builtins.txt
+++ b/docs/ref/templates/builtins.txt
@@ -313,6 +313,20 @@ displayed by the ``{{ athlete_list|length }}`` variable.
 As you can see, the ``if`` tag can take an optional ``{% else %}`` clause that
 will be displayed if the test fails.
 
+.. versionadded:: 1.2
+
+If you have multiple conditions to check against, you may wish to use
+the ``elif`` tag::
+
+    {% if athlete_list %}
+        Number of athletes: {{ athlete_list|length }}
+    {% elif athletes_in_lockerroom %}
+        There are some athletes queued in the locker room, but they
+        should be out soon!
+    {% else %}
+        No athletes.
+    {% endif %}
+
 Boolean operators
 ^^^^^^^^^^^^^^^^^
 
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 2946208..99aacff 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -542,6 +542,13 @@ class Templates(unittest.TestCase):
             'if-tag02': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": False}, "no"),
             'if-tag03': ("{% if foo %}yes{% else %}no{% endif %}", {}, "no"),
 
+            'if-tag04': ("{% if foo %}foo{% elif bar %}bar{% else %}nothing{%endif%}",
+                         {'foo': True}, "foo"),
+            'if-tag05': ("{% if foo %}foo{% elif bar %}bar{% else %}nothing{%endif%}",
+                         {'bar': True}, "bar"),
+            'if-tag06': ("{% if foo %}foo{% elif bar %}bar{% else %}nothing{%endif%}",
+                         {}, "nothing"),
+
             # Filters
             'if-tag-filter01': ("{% if foo|length == 5 %}yes{% else %}no{% endif %}", {'foo': 'abcde'}, "yes"),
             'if-tag-filter02': ("{% if foo|upper == 'ABC' %}yes{% else %}no{% endif %}", {}, "no"),
@@ -741,14 +748,11 @@ class Templates(unittest.TestCase):
             'namedendblocks01': ("1{% block first %}_{% block second %}2{% endblock second %}_{% endblock first %}3", {}, '1_2_3'),
 
             # Unbalanced blocks
-            'namedendblocks02': ("1{% block first %}_{% block second %}2{% endblock first %}_{% endblock second %}3", {}, template.TemplateSyntaxError),
-            'namedendblocks03': ("1{% block first %}_{% block second %}2{% endblock %}_{% endblock second %}3", {}, template.TemplateSyntaxError),
-            'namedendblocks04': ("1{% block first %}_{% block second %}2{% endblock second %}_{% endblock third %}3", {}, template.TemplateSyntaxError),
-            'namedendblocks05': ("1{% block first %}_{% block second %}2{% endblock first %}", {}, template.TemplateSyntaxError),
+            'namedendblocks02': ("1{% block first %}_{% block second %}2{% endblock first %}", {}, template.TemplateSyntaxError),
 
             # Mixed named and unnamed endblocks
-            'namedendblocks06': ("1{% block first %}_{% block second %}2{% endblock %}_{% endblock first %}3", {}, '1_2_3'),
-            'namedendblocks07': ("1{% block first %}_{% block second %}2{% endblock second %}_{% endblock %}3", {}, '1_2_3'),
+            'namedendblocks03': ("1{% block first %}_{% block second %}2{% endblock %}_{% endblock first %}3", {}, '1_2_3'),
+            'namedendblocks04': ("1{% block first %}_{% block second %}2{% endblock second %}_{% endblock %}3", {}, '1_2_3'),
 
             ### INHERITANCE ###########################################################
 
