Ticket #6351: filter_doc.diff

File filter_doc.diff, 8.2 KB (added by David Tulig, 16 years ago)

Turned ticket description into a patch

  • docs/templates.txt

    diff --git a/docs/templates.txt b/docs/templates.txt
    index c351c95..4da1679 100644
    a b add  
    12241224
    12251225Adds the arg to the value.
    12261226
     1227For example::
     1228
     1229    {{ value|add:2 }}
     1230
     1231If ``value`` is 4, then the output will be 6.
     1232
    12271233addslashes
    12281234~~~~~~~~~~
    12291235
    cut  
    12471253
    12481254Removes all values of arg from the given string.
    12491255
     1256For example::
     1257
     1258    {{ value|cut:" "}}
     1259
     1260If ``value`` is "String with spaces", the output will be ``Stringwithspaces``.
     1261
    12501262date
    12511263~~~~
    12521264
    12531265Formats a date according to the given format (same as the `now`_ tag).
    12541266
     1267For example::
     1268
     1269    {{ value|date:"D d M Y" }}
     1270
     1271If ``value`` is a datetime object (ie. datetime.datetime.now()), the output
     1272would be formatted like ``Wed 09 Jan 2008``.
     1273
    12551274default
    12561275~~~~~~~
    12571276
    12581277If value is unavailable, use given default.
    12591278
     1279For example::
     1280
     1281    {{ value|default:"nothing" }}
     1282
     1283If ``value`` is ``Undefined``, the output would be ``nothing``.
     1284
    12601285default_if_none
    12611286~~~~~~~~~~~~~~~
    12621287
    12631288If value is ``None``, use given default.
    12641289
     1290For example::
     1291
     1292    {{ value|default_if_none:"nothing" }}
     1293
     1294If ``value`` is ``None``, the output would be ``nothing``.
     1295
    12651296dictsort
    12661297~~~~~~~~
    12671298
    12681299Takes a list of dictionaries, returns that list sorted by the key given in
    12691300the argument.
    12701301
     1302For example::
     1303
     1304    {{ value|dictsort:"n" }}
     1305
     1306If ``value`` is ``[{'n': 'g', 'm': 0}, {'n': 'a', 'm': 2}, {'n': 'z', 'm':
     1307    8}]``, the output would be ``[{'n': 'a', 'm': 2}, {'n': 'g', 'm': 0}, {'n': 'z', 'm':
     1308    8}]``.
     1309
    12711310dictsortreversed
    12721311~~~~~~~~~~~~~~~~
    12731312
    12741313Takes a list of dictionaries, returns that list sorted in reverse order by the
    12751314key given in the argument.
    12761315
     1316For example::
     1317
     1318    {{ value|dictsortreversed:"n" }}
     1319
     1320If ``value`` is ``[{'n': 'g', 'm': 0}, {'n': 'a', 'm': 2}, {'n': 'z', 'm':
     1321    8}]``, the output would be ``[{'n': 'z', 'm': 8}, {'n': 'g', 'm': 0}, {'n': 'a', 'm':
     1322    2}]``.
     1323
    12771324divisibleby
    12781325~~~~~~~~~~~
    12791326
    12801327Returns true if the value is divisible by the argument.
    12811328
     1329For example::
     1330
     1331    {{ value|divisibleby:3 }}
     1332
     1333If ``value`` is 123456789, the output would be ``True``.
     1334
    12821335escape
    12831336~~~~~~
    12841337
    filesizeformat  
    13191372Format the value like a 'human-readable' file size (i.e. ``'13 KB'``,
    13201373``'4.1 MB'``, ``'102 bytes'``, etc).
    13211374
     1375For example::
     1376
     1377    {{ value|filesizeformat }}
     1378
     1379If ``value`` is 123456789, the output would be ``117.7 MB``.
     1380
    13221381first
    13231382~~~~~
    13241383
    13251384Returns the first item in a list.
    13261385
     1386For example::
     1387
     1388    {{ value|first }}
     1389
     1390If ``value`` is ``['a', 'b', 'c']``, the output would be `a`.
     1391
    13271392fix_ampersands
    13281393~~~~~~~~~~~~~~
    13291394
    13301395Replaces ampersands with ``&`` entities.
    13311396
     1397For example::
     1398
     1399    {{ value|fix_ampersands }}
     1400
     1401If ``value`` is ``Tom & Jerry``, the output would be ``Tom & Jerry``.
     1402
    13321403floatformat
    13331404~~~~~~~~~~~
    13341405
    right-most digit, 2 is the second-right-most digit, etc. Returns the original  
    13881459value for invalid input (if input or argument is not an integer, or if argument
    13891460is less than 1). Otherwise, output is always an integer.
    13901461
     1462For example::
     1463   
     1464    {{ value|get_digit:2 }}
     1465
     1466If ``value`` is 123456789, the output would be ``8``.
     1467
    13911468iriencode
    13921469~~~~~~~~~
    13931470
    join  
    14031480
    14041481Joins a list with a string, like Python's ``str.join(list)``.
    14051482
     1483For example::
     1484
     1485    {{ value|join:" or " }}
     1486
     1487If ``value`` is ``['a', 'b', 'c', 'd']``, the output would be ``a or be or c
     1488or d``.
     1489
    14061490last
    14071491~~~~
    14081492
    14091493Returns the last item in a list.
    14101494
     1495For example::
     1496
     1497    {{ value|last }}
     1498
     1499If ``value`` is ``['a', 'b', 'c', 'd']``, the output would be ``d``.
     1500
    14111501length
    14121502~~~~~~
    14131503
    14141504Returns the length of the value. Useful for lists.
    14151505
     1506For example::
     1507
     1508    {{ value|length }}
     1509
     1510If ``value`` is ``['a', 'b', 'c', 'd']``, the output would be ``4``.
     1511
    14161512length_is
    14171513~~~~~~~~~
    14181514
    14191515Returns a boolean of whether the value's length is the argument.
    14201516
     1517For example::
     1518
     1519    {{ value|length_is:4 }}
     1520
     1521If ``value`` is ``['a', 'b', 'c', 'd']``, the output would be ``4``.
     1522
    14211523linebreaks
    14221524~~~~~~~~~~
    14231525
    Replaces line breaks in plain text with appropriate HTML; a single  
    14251527newline becomes an HTML line break (``<br />``) and a new line
    14261528followed by a blank line becomes a paragraph break (``</p>``).
    14271529
     1530For example::
     1531
     1532    {{ value|linebreaks }}
     1533
     1534If ``value`` is ``Joel\nis a slug``, the output would be ``<p>Joe<br>is a
     1535slug</p>``.
     1536
    14281537linebreaksbr
    14291538~~~~~~~~~~~~
    14301539
    lower  
    14481557
    14491558Converts a string into all lowercase.
    14501559
     1560For example::
     1561
     1562    {{ value|lower }}
     1563
     1564If ``value`` is ``Joel Is a Slug``, the output would be ``joel is a slug``.
     1565
    14511566make_list
    14521567~~~~~~~~~
    14531568
    14541569Returns the value turned into a list. For an integer, it's a list of
    14551570digits. For a string, it's a list of characters.
    14561571
     1572For example::
     1573
     1574    {{ value|make_list }}
     1575
     1576If ``value`` is 123456789, the output would be ``[u'1', u'2', u'3', u'4',
     1577   u'5', u'6', u'7', u'8', u'9']``
     1578If ``value`` is 123456789, the output would be ``[u'J', u'o', u'e', u'l',
     1579   u'i', u's', u'a', u's', u'l', u'u', u'g']``
     1580
    14571581phone2numeric
    14581582~~~~~~~~~~~~~
    14591583
    random  
    14971621
    14981622Returns a random item from the list.
    14991623
     1624For example::
     1625
     1626    {{ value|random }}
     1627
     1628If ``value`` is ``['a', 'b', 'c', 'd']``, the output could be ``b``.
     1629
    15001630removetags
    15011631~~~~~~~~~~
    15021632
    15031633Removes a space separated list of [X]HTML tags from the output.
    15041634
     1635For example::
     1636
     1637    {{ value|removetags:"b span"|safe }}
     1638
     1639If ``value`` is ``<b>Joel</b> <button>is</button> a <span>slug</span>`` the
     1640output would be ``Joel <button>is</button> a slug``.
     1641
    15051642rjust
    15061643~~~~~
    15071644
    Converts to lowercase, removes non-word characters (alphanumerics and  
    15331670underscores) and converts spaces to hyphens. Also strips leading and trailing
    15341671whitespace.
    15351672
     1673For example::
     1674
     1675    {{ value|slugify }}
     1676
     1677If ``value`` is ``Joel is a slug``, the output would be ``joel-is-a-slug``.
     1678
    15361679stringformat
    15371680~~~~~~~~~~~~
    15381681
    the leading "%" is dropped.  
    15431686See http://docs.python.org/lib/typesseq-strings.html for documentation of
    15441687Python string formatting
    15451688
     1689For example::
     1690
     1691    {{ value|stringformat:"s" }}
     1692
     1693If ``value`` is ``Joel is a slug``, the output would be ``Joel is a slug``.
     1694
    15461695striptags
    15471696~~~~~~~~~
    15481697
    15491698Strips all [X]HTML tags.
    15501699
     1700For example::
     1701
     1702    {{ value|striptags }}
     1703
     1704If ``value`` is ``<b>Joel</b> <button>is</button> a <span>slug</span>`` the
     1705output would be ``Joel is a slug``.
     1706
    15511707time
    15521708~~~~
    15531709
    The time filter will only accept parameters in the format string that relate  
    15561712to the time of day, not the date (for obvious reasons). If you need to
    15571713format a date, use the `date`_ filter.
    15581714
     1715For example::
     1716
     1717    {{ value|time:"H:i" }}
     1718
     1719If ``value`` is ``datetime.datetime.now()``, the output would be formatted
     1720like ``01:23``.
     1721
    15591722timesince
    15601723~~~~~~~~~
    15611724
    Truncates a string after a certain number of words.  
    15971760
    15981761**Argument:** Number of words to truncate after
    15991762
     1763For example::
     1764
     1765    {{ value|truncatewords:2 }}
     1766
     1767If ``value`` is ``Joel is a slug``, the output would be ``Joel is ...``.
     1768
    16001769truncatewords_html
    16011770~~~~~~~~~~~~~~~~~~
    16021771
    upper  
    16421811
    16431812Converts a string into all uppercase.
    16441813
     1814For example::
     1815
     1816    {{ value|upper }}
     1817
     1818If ``value`` is ``Joel is a slug``, the output would be ``JOEL IS A SLUG``.
     1819
    16451820urlencode
    16461821~~~~~~~~~
    16471822
    Converts URLs in plain text into clickable links.  
    16551830Note that if ``urlize`` is applied to text that already contains HTML markup,
    16561831things won't work as expected. Apply this filter only to *plain* text.
    16571832
     1833For example::
     1834
     1835    {{ value|urlize }}
     1836
     1837If ``value`` is ``Check out www.djangoproject.com``, the output would be
     1838``Check out <a
     1839href="http://www.djangoproject.com">www.djangoproject.com</a>``.
     1840
    16581841urlizetrunc
    16591842~~~~~~~~~~~
    16601843
    As with urlize_, this filter should only be applied to *plain* text.  
    16651848
    16661849**Argument:** Length to truncate URLs to
    16671850
     1851For example::
     1852
     1853    {{ value|urlizetrunc:15 }}
     1854
     1855If ``value`` is ``Check out www.djangoproject.com``, the output would be
     1856``Check out <a
     1857href="http://www.djangoproject.com">www.djangopr...</a>``.
     1858
    16681859wordcount
    16691860~~~~~~~~~
    16701861
    Wraps words at specified line length.  
    16771868
    16781869**Argument:** number of characters at which to wrap the text
    16791870
     1871For example::
     1872
     1873    {{ value|wordwrap:5 }}
     1874
     1875If ``value`` is ``Joel is a slug``, the output would be::
     1876
     1877    Joel
     1878    is a
     1879    slug
     1880
    16801881yesno
    16811882~~~~~
    16821883
Back to Top