Ticket #16939: r17141-howto-custom-template-tags-comment.diff

File r17141-howto-custom-template-tags-comment.diff, 1.6 KB (added by Sebastian Goll, 13 years ago)
  • docs/howto/custom-template-tags.txt

     
    11551155To create a template tag such as this, use ``parser.parse()`` in your
    11561156compilation function.
    11571157
    1158 Here's how the standard :ttag:`{% comment %}<comment>` tag is implemented:
     1158Here's how a simplified ``{% comment %}`` tag might be implemented:
    11591159
    11601160.. code-block:: python
    11611161
     
    11681168        def render(self, context):
    11691169            return ''
    11701170
     1171.. note::
     1172    The actual implementation of :ttag:`{% comment %}<comment>` is slightly
     1173    different in that it allows broken template tags to appear between
     1174    ``{% comment %}`` and ``{% endcomment %}``. It does so by calling
     1175    ``parser.skip_past('endcomment')`` instead of ``parser.parse(('endcomment',))``
     1176    followed by ``parser.delete_first_token()``, thus avoiding the generation of a
     1177    node list.
     1178
    11711179``parser.parse()`` takes a tuple of names of block tags ''to parse until''. It
    11721180returns an instance of ``django.template.NodeList``, which is a list of
    11731181all ``Node`` objects that the parser encountered ''before'' it encountered
  • docs/ref/templates/builtins.txt

     
    5151comment
    5252^^^^^^^
    5353
    54 Ignores everything between ``{% comment %}`` and ``{% endcomment %}``
     54Ignores everything between ``{% comment %}`` and ``{% endcomment %}``.
    5555
    5656.. templatetag:: csrf_token
    5757
Back to Top