Hi,

I have a suggestion (with a patch) to save a few key clicks :-)
Do you ever write a template with {% block ... %}{% endblock %} tags
solely as placeholders to be overridden by other templates? I find I am
doing this a lot... and I am too lazy to type the {% endblock %} each
time :-) so I added the {% eblock ... %} tag that does not require an
end tag.

And here is the patch. I am posting it here to see if people think this
is a good idea... if it is, I will create a ticket.

--
Thanks a lot,
Medhat

Index: loader_tags.py
===================================================================
--- loader_tags.py      (revision 3611)
+++ loader_tags.py      (working copy)
@@ -1,5 +1,5 @@
 from django.template import TemplateSyntaxError, TemplateDoesNotExist,
resolve_variable
-from django.template import Library, Node
+from django.template import Library, Node, NodeList
 from django.template.loader import get_template,
get_template_from_string, find_template_source
 from django.conf import settings

@@ -112,27 +112,32 @@
             return ''
         except:
             return '' # Fail silently for invalid included templates.
-
-def do_block(parser, token):
-    """
-    Define a block that can be overridden by child templates.
-    """
-    bits = token.contents.split()
-    if len(bits) != 2:
-        raise TemplateSyntaxError, "'%s' tag takes only one argument"
% bits[0]
-    block_name = bits[1]
-    # Keep track of the names of BlockNodes found in this template, so
we can
-    # check for duplication.
-    try:
-        if block_name in parser.__loaded_blocks:
-            raise TemplateSyntaxError, "'%s' tag with name '%s'
appears more than once" % (bits[0], block_name)
-        parser.__loaded_blocks.append(block_name)
-    except AttributeError: # parser.__loaded_blocks isn't a list yet
-        parser.__loaded_blocks = [block_name]
-    nodelist = parser.parse(('endblock',))
-    parser.delete_first_token()
-    return BlockNode(block_name, nodelist)
-
+
+def do_block_func(empty=False):
+    def do_block(parser,token):
+        """
+        Define a block that can be overridden by child templates.
+        """
+        bits = token.contents.split()
+        if len(bits) != 2:
+            raise TemplateSyntaxError, "'%s' tag takes only one
argument" % bits[0]
+        block_name = bits[1]
+        # Keep track of the names of BlockNodes found in this
template, so we can
+        # check for duplication.
+        try:
+            if block_name in parser.__loaded_blocks:
+                raise TemplateSyntaxError, "'%s' tag with name '%s'
appears more than once" % (bits[0], block_name)
+            parser.__loaded_blocks.append(block_name)
+        except AttributeError: # parser.__loaded_blocks isn't a list
yet
+            parser.__loaded_blocks = [block_name]
+        if empty:
+            nodelist = NodeList()
+        else:
+            nodelist = parser.parse(('endblock',))
+            parser.delete_first_token()
+        return BlockNode(block_name, nodelist)
+    return do_block
+
 def do_extends(parser, token):
     """
     Signal that this template extends a parent template.
@@ -172,6 +177,7 @@
         return ConstantIncludeNode(path[1:-1])
     return IncludeNode(bits[1])

-register.tag('block', do_block)
+register.tag('block', do_block_func())
+register.tag('eblock', do_block_func(True))
 register.tag('extends', do_extends)
 register.tag('include', do_include)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to