Index: django/template/__init__.py
===================================================================
--- django/template/__init__.py	(revision 9109)
+++ django/template/__init__.py	(working copy)
@@ -739,6 +739,7 @@
     # Set this to True for nodes that must be first in the template (although
     # they can be preceded by text nodes.
     must_be_first = False
+    child_nodelists = ('nodelist',)
 
     def render(self, context):
         "Return the node rendered as a string"
@@ -752,8 +753,10 @@
         nodes = []
         if isinstance(self, nodetype):
             nodes.append(self)
-        if hasattr(self, 'nodelist'):
-            nodes.extend(self.nodelist.get_nodes_by_type(nodetype))
+        for attr in self.child_nodelists:
+            nodelist = getattr(self, attr, None)
+            if nodelist:
+                nodes.extend(nodelist.get_nodes_by_type(nodetype))
         return nodes
 
 class NodeList(list):
Index: django/template/defaulttags.py
===================================================================
--- django/template/defaulttags.py	(revision 9109)
+++ django/template/defaulttags.py	(working copy)
@@ -8,7 +8,7 @@
 except NameError:
     from django.utils.itercompat import reversed     # Python 2.3 fallback
 
-from django.template import Node, NodeList, Template, Context, Variable
+from django.template import Node, NodeList, Template, Variable
 from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END, COMMENT_TAG_START, COMMENT_TAG_END
 from django.template import get_library, Library, InvalidTemplateLibrary
 from django.conf import settings
@@ -83,6 +83,8 @@
         return u''
 
 class ForNode(Node):
+    child_nodelists = ('nodelist_loop',)
+
     def __init__(self, loopvars, sequence, is_reversed, nodelist_loop):
         self.loopvars, self.sequence = loopvars, sequence
         self.is_reversed = is_reversed
@@ -98,13 +100,6 @@
         for node in self.nodelist_loop:
             yield node
 
-    def get_nodes_by_type(self, nodetype):
-        nodes = []
-        if isinstance(self, nodetype):
-            nodes.append(self)
-        nodes.extend(self.nodelist_loop.get_nodes_by_type(nodetype))
-        return nodes
-
     def render(self, context):
         nodelist = NodeList()
         if 'forloop' in context:
@@ -190,6 +185,8 @@
         return ''
 
 class IfEqualNode(Node):
+    child_nodelists = ('nodelist_true', 'nodelist_false')
+
     def __init__(self, var1, var2, nodelist_true, nodelist_false, negate):
         self.var1, self.var2 = Variable(var1), Variable(var2)
         self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
@@ -212,6 +209,8 @@
         return self.nodelist_false.render(context)
 
 class IfNode(Node):
+    child_nodelists = ('nodelist_true', 'nodelist_false',)
+
     def __init__(self, bool_exprs, nodelist_true, nodelist_false, link_type):
         self.bool_exprs = bool_exprs
         self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
@@ -226,14 +225,6 @@
         for node in self.nodelist_false:
             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))
-        return nodes
-
     def render(self, context):
         if self.link_type == IfNode.LinkTypes.or_:
             for ifnot, bool_expr in self.bool_exprs:
Index: tests/regressiontests/templates/tests.py
===================================================================
--- tests/regressiontests/templates/tests.py	(revision 9109)
+++ tests/regressiontests/templates/tests.py	(working copy)
@@ -732,6 +732,27 @@
             # Inheritance from a template that doesn't have any blocks
             'inheritance27': ("{% extends 'inheritance26' %}", {}, 'no tags'),
 
+            # Base template, putting block in a conditional {% if %} tag
+            'inheritance28': ("1{% if optional %}{% block opt %}2{% endblock %}{% endif %}3", {'optional': True}, '123'),
+
+            # Inherit from a template with block wrapped in an {% if %} tag (in parent), still gets overridden
+            'inheritance29': ("{% extends 'inheritance28' %}{% block opt %}two{% endblock %}", {'optional': True}, '1two3'),
+            'inheritance30': ("{% extends 'inheritance28' %}{% block opt %}two{% endblock %}", {}, '13'),
+
+            # Base template, putting block in a conditional {% ifequal %} tag
+            'inheritance31': ("1{% ifequal optional 1 %}{% block opt %}2{% endblock %}{% endifequal %}3", {'optional': 1}, '123'),
+
+            # Inherit from a template with block wrapped in an {% ifequal %} tag (in parent), still gets overridden
+            'inheritance32': ("{% extends 'inheritance31' %}{% block opt %}two{% endblock %}", {'optional': 1}, '1two3'),
+            'inheritance33': ("{% extends 'inheritance31' %}{% block opt %}two{% endblock %}", {'optional': 2}, '13'),
+
+            # Base template, putting block in a {% for %} tag
+            'inheritance34': ("{% for n in numbers %}_{% block for %}{{ n }}{% endblock %}{% endfor %}_", {'numbers': '123'}, '_1_2_3_'),
+
+            # Inherit from a template with block wrapped in an {% for %} tag (in parent), still gets overridden
+            'inheritance35': ("{% extends 'inheritance34' %}{% block for %}X{% endblock %}", {'numbers': '123'}, '_X_X_X_'),
+            'inheritance36': ("{% extends 'inheritance34' %}{% block for %}X{% endblock %}", {}, '_'),
+
             ### I18N ##################################################################
 
             # {% spaceless %} tag
