Changeset 3772
- Timestamp:
- 09/21/06 06:41:18 (2 years ago)
- Files:
-
- django/trunk/docs/templates_python.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/templates_python.txt
r3717 r3772 764 764 ~~~~~~~~~~~~~~~~~~~~~~~~ 765 765 766 Many template tags take a single argument -- a string or a template variable767 reference-- and return a string after doing some processing based solely on766 Many template tags take a number of arguments -- strings or a template variables 767 -- and return a string after doing some processing based solely on 768 768 the input argument and some external information. For example, the 769 769 ``current_time`` tag we wrote above is of this variety: we give it a format … … 772 772 To ease the creation of the types of tags, Django provides a helper function, 773 773 ``simple_tag``. This function, which is a method of 774 ``django.template.Library``, takes a function that accepts one argument, wraps775 it in a ``render`` function and the other necessary bits mentioned above and 776 registers it with the template system.774 ``django.template.Library``, takes a function that accepts any number of 775 arguments, wraps it in a ``render`` function and the other necessary bits 776 mentioned above and registers it with the template system. 777 777 778 778 Our earlier ``current_time`` function could thus be written like this:: … … 790 790 791 791 A couple of things to note about the ``simple_tag`` helper function: 792 * Only the (single) argument is passed into our function.793 792 * Checking for the required number of arguments, etc, has already been 794 793 done by the time our function is called, so we don't need to do that. 795 794 * The quotes around the argument (if any) have already been stripped away, 796 795 so we just receive a plain string. 796 * If the argument was a template variable, our function is passed the 797 current value of the variable, not the variable itself. 798 799 When your template tag does not need access to the current context, writing a 800 function to work with the input values and using the ``simple_tag`` helper is 801 the easiest way to create a new tag. 797 802 798 803 Inclusion tags
