Changeset 7280
- Timestamp:
- 03/17/08 23:21:08 (6 months ago)
- Files:
-
- django/trunk/docs/templates.txt (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/templates.txt
r7276 r7280 1223 1223 ~~~ 1224 1224 1225 Adds the arg to the value.1226 1227 For example:: 1228 1229 {{ value|add: 2}}1230 1231 If ``value`` is 4, then the output will be 6.1225 Adds the argument to the value. 1226 1227 For example:: 1228 1229 {{ value|add:"2" }} 1230 1231 If ``value`` is ``4``, then the output will be ``6``. 1232 1232 1233 1233 addslashes … … 1236 1236 Adds slashes before quotes. Useful for escaping strings in CSV, for example. 1237 1237 1238 **New in Django development version**: for escaping data in JavaScript strings,1238 **New in Django development version**: For escaping data in JavaScript strings, 1239 1239 use the `escapejs`_ filter instead. 1240 1240 … … 1258 1258 {{ value|cut:" "}} 1259 1259 1260 If ``value`` is "String with spaces", the output will be ``Stringwithspaces``.1260 If ``value`` is ``"String with spaces"``, the output will be ``"Stringwithspaces"``. 1261 1261 1262 1262 date … … 1269 1269 {{ value|date:"D d M Y" }} 1270 1270 1271 If ``value`` is a datetime object (ie. datetime.datetime.now()), the output 1272 would be formatted like ``Wed 09 Jan 2008``. 1271 If ``value`` is a ``datetime`` object (e.g., the result of 1272 ``datetime.datetime.now()``), the output will be the string 1273 ``'Wed 09 Jan 2008'``. 1273 1274 1274 1275 default 1275 1276 ~~~~~~~ 1276 1277 1277 If value is unavailable, use given default.1278 If value evaluates to ``False``, use given default. Otherwise, use the value. 1278 1279 1279 1280 For example:: … … 1281 1282 {{ value|default:"nothing" }} 1282 1283 1283 If ``value`` is `` Undefined``, the output wouldbe ``nothing``.1284 If ``value`` is ``""`` (the empty string), the output will be ``nothing``. 1284 1285 1285 1286 default_if_none 1286 1287 ~~~~~~~~~~~~~~~ 1287 1288 1288 If value is ``None``, use given default. 1289 If (and only if) value is ``None``, use given default. Otherwise, use the 1290 value. 1291 1292 Note that if an empty string is given, the default value will *not* be used. 1293 Use the ``default`` filter if you want to fallback for empty strings. 1289 1294 1290 1295 For example:: … … 1292 1297 {{ value|default_if_none:"nothing" }} 1293 1298 1294 If ``value`` is ``None``, the output w ould be ``nothing``.1299 If ``value`` is ``None``, the output will be the string ``"nothing"``. 1295 1300 1296 1301 dictsort 1297 1302 ~~~~~~~~ 1298 1303 1299 Takes a list of dictionaries ,returns that list sorted by the key given in1304 Takes a list of dictionaries and returns that list sorted by the key given in 1300 1305 the argument. 1301 1306 … … 1305 1310 1306 1311 If ``value`` is:: 1307 1312 1308 1313 [ 1309 {'name': 'zed', 'age': 19} 1310 {'name': 'amy', 'age': 22}, 1311 {'name': 'joe', 'age': 31}, 1314 {'name': 'zed', 'age': 19}, 1315 {'name': 'amy', 'age': 22}, 1316 {'name': 'joe', 'age': 31}, 1312 1317 ] 1313 1318 … … 1315 1320 1316 1321 [ 1317 {'name': 'amy', 'age': 22}, 1318 {'name': 'joe', 'age': 31}, 1319 {'name': 'zed', 'age': 19} 1322 {'name': 'amy', 'age': 22}, 1323 {'name': 'joe', 'age': 31}, 1324 {'name': 'zed', 'age': 19}, 1320 1325 ] 1321 1326 … … 1323 1328 ~~~~~~~~~~~~~~~~ 1324 1329 1325 Takes a list of dictionaries , returns that list sorted in reverse order by the1326 key given in the argument. This works exactly the same as the above filter, but 1327 the returned value will be in reverse order.1330 Takes a list of dictionaries and returns that list sorted in reverse order by 1331 the key given in the argument. This works exactly the same as the above filter, 1332 but the returned value will be in reverse order. 1328 1333 1329 1334 divisibleby 1330 1335 ~~~~~~~~~~~ 1331 1336 1332 Returns trueif the value is divisible by the argument.1333 1334 For example:: 1335 1336 {{ value|divisibleby: 3}}1337 Returns ``True`` if the value is divisible by the argument. 1338 1339 For example:: 1340 1341 {{ value|divisibleby:"3" }} 1337 1342 1338 1343 If ``value`` is ``21``, the output would be ``True``. … … 1340 1345 escape 1341 1346 ~~~~~~ 1342 1343 **New in Django development version:** The behaviour of this filter has1344 changed slightly in the development version (the affects are only applied1345 once, after all other filters).1346 1347 1347 1348 Escapes a string's HTML. Specifically, it makes these replacements: … … 1363 1364 multiple escaping passes to be applied, use the ``force_escape`` filter. 1364 1365 1366 **New in Django development version:** Due to auto-escaping, the behavior of 1367 this filter has changed slightly. The replacements are only made once, after 1368 all other filters are applied -- including filters before and after it. 1369 1365 1370 escapejs 1366 1371 ~~~~~~~~ … … 1393 1398 {{ value|first }} 1394 1399 1395 If ``value`` is ``['a', 'b', 'c']``, the output would be `a`.1400 If ``value`` is the list ``['a', 'b', 'c']``, the output will be ``'a'``. 1396 1401 1397 1402 fix_ampersands … … 1404 1409 {{ value|fix_ampersands }} 1405 1410 1406 If ``value`` is ``Tom & Jerry``, the output w ouldbe ``Tom & Jerry``.1407 1408 **New in Django development version**: you probably don't need to use this1409 filter since ampersands will be automatically escaped. See escape_ for more on 1410 how auto-escaping works.1411 If ``value`` is ``Tom & Jerry``, the output will be ``Tom & Jerry``. 1412 1413 **New in Django development version**: This filter generally is no longer 1414 useful, because ampersands are automatically escaped in templates. See escape_ 1415 for more on how auto-escaping works. 1411 1416 1412 1417 floatformat … … 1464 1469 ~~~~~~~~~ 1465 1470 1466 Given a whole number, returns the requested digit of it, where 1 is the1467 right-most digit, 2 is the second-right-most digit, etc. Returns the original 1468 value for invalid input (if input or argument is not an integer, or if argument 1469 is lessthan 1). Otherwise, output is always an integer.1470 1471 For example:: 1472 1473 {{ value|get_digit: 2}}1474 1475 If ``value`` is 123456789, the output wouldbe ``8``.1471 Given a whole number, returns the requested digit, where 1 is the right-most 1472 digit, 2 is the second-right-most digit, etc. Returns the original value for 1473 invalid input (if input or argument is not an integer, or if argument is less 1474 than 1). Otherwise, output is always an integer. 1475 1476 For example:: 1477 1478 {{ value|get_digit:"2" }} 1479 1480 If ``value`` is ``123456789``, the output will be ``8``. 1476 1481 1477 1482 iriencode … … 1494 1499 {{ value|join:" // " }} 1495 1500 1496 If ``value`` is ``['a', 'b', 'c']``, the output would be ``a // b // c``. 1501 If ``value`` is the list ``['a', 'b', 'c']``, the output will be the string 1502 ``"a // b // c"``. 1497 1503 1498 1504 last … … 1507 1513 {{ value|last }} 1508 1514 1509 If ``value`` is ``['a', 'b', 'c', 'd']``, the output would be ``d``. 1515 If ``value`` is the list ``['a', 'b', 'c', 'd']``, the output will be the string 1516 ``"d"``. 1510 1517 1511 1518 length 1512 1519 ~~~~~~ 1513 1520 1514 Returns the length of the value. Useful forlists.1521 Returns the length of the value. This works for both strings and lists. 1515 1522 1516 1523 For example:: … … 1518 1525 {{ value|length }} 1519 1526 1520 If ``value`` is ``['a', 'b', 'c', 'd']``, the output w ouldbe ``4``.1527 If ``value`` is ``['a', 'b', 'c', 'd']``, the output will be ``4``. 1521 1528 1522 1529 length_is 1523 1530 ~~~~~~~~~ 1524 1531 1525 Returns a boolean of whether the value's length is the argument.1526 1527 For example:: 1528 1529 {{ value|length_is: 4}}1530 1531 If ``value`` is ``['a', 'b', 'c', 'd']``, the output w ouldbe ``True``.1532 Returns ``True`` if the value's length is the argument, or ``False`` otherwise. 1533 1534 For example:: 1535 1536 {{ value|length_is:"4" }} 1537 1538 If ``value`` is ``['a', 'b', 'c', 'd']``, the output will be ``True``. 1532 1539 1533 1540 linebreaks … … 1542 1549 {{ value|linebreaks }} 1543 1550 1544 If ``value`` is ``Joel\nis a slug``, the output w ouldbe ``<p>Joe<br>is a1551 If ``value`` is ``Joel\nis a slug``, the output will be ``<p>Joe<br>is a 1545 1552 slug</p>``. 1546 1553 … … 1572 1579 {{ value|lower }} 1573 1580 1574 If ``value`` is `` Joel Is a Slug``, the output would be ``joel is a slug``.1581 If ``value`` is ``Still MAD At Yoko``, the output will be ``still mad at yoko``. 1575 1582 1576 1583 make_list … … 1584 1591 {{ value|make_list }} 1585 1592 1586 If ``value`` is "Joe", the output would be ``[u'J', u'o', u'e']. If ``value`` is 1587 123, the output would be ``[1, 2, 3]``. 1593 If ``value`` is the string ``"Joe"``, the output would be the list 1594 ``[u'J', u'o', u'e']``. If ``value`` is ``123``, the output will be the list 1595 ``[1, 2, 3]``. 1588 1596 1589 1597 phone2numeric … … 1630 1638 ~~~~~~ 1631 1639 1632 Returns a random item from the list.1640 Returns a random item from the given list. 1633 1641 1634 1642 For example:: … … 1636 1644 {{ value|random }} 1637 1645 1638 If ``value`` is ``['a', 'b', 'c', 'd']``, the output could be ``b``.1646 If ``value`` is the list ``['a', 'b', 'c', 'd']``, the output could be ``"b"``. 1639 1647 1640 1648 removetags 1641 1649 ~~~~~~~~~~ 1642 1650 1643 Removes a space separated list of [X]HTML tags from the output.1651 Removes a space-separated list of [X]HTML tags from the output. 1644 1652 1645 1653 For example:: … … 1647 1655 {{ value|removetags:"b span"|safe }} 1648 1656 1649 If ``value`` is `` <b>Joel</b> <button>is</button> a <span>slug</span>`` the1650 output w ould be ``Joel <button>is</button> a slug``.1657 If ``value`` is ``"<b>Joel</b> <button>is</button> a <span>slug</span>"`` the 1658 output will be ``"Joel <button>is</button> a slug"``. 1651 1659 1652 1660 rjust … … 1685 1693 {{ value|slugify }} 1686 1694 1687 If ``value`` is `` Joel is a slug``, the output would be ``joel-is-a-slug``.1695 If ``value`` is ``"Joel is a slug"``, the output will be ``"joel-is-a-slug"``. 1688 1696 1689 1697 stringformat … … 1701 1709 {{ value|stringformat:"s" }} 1702 1710 1703 If ``value`` is `` Joel is a slug``, the output would be ``Joel is a slug``.1711 If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is a slug"``. 1704 1712 1705 1713 striptags … … 1712 1720 {{ value|striptags }} 1713 1721 1714 If ``value`` is `` <b>Joel</b> <button>is</button> a <span>slug</span>``the1715 output w ould be ``Joel is a slug``.1722 If ``value`` is ``"<b>Joel</b> <button>is</button> a <span>slug</span>"``, the 1723 output will be ``"Joel is a slug"``. 1716 1724 1717 1725 time … … 1727 1735 {{ value|time:"H:i" }} 1728 1736 1729 If ``value`` is ``datetime.datetime.now()``, the output would be formatted1730 like ``01:23``.1737 If ``value`` is equivalent to ``datetime.datetime.now()``, the output will be 1738 the string ``"01:23"``. 1731 1739 1732 1740 timesince 1733 1741 ~~~~~~~~~ 1734 1742 1735 Formats a date as the time since that date ( i.e."4 days, 6 hours").1743 Formats a date as the time since that date (e.g., "4 days, 6 hours"). 1736 1744 1737 1745 Takes an optional argument that is a variable containing the date to use as … … 1775 1783 {{ value|truncatewords:2 }} 1776 1784 1777 If ``value`` is `` Joel is a slug``, the output would be ``Joel is ...``.1785 If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is ..."``. 1778 1786 1779 1787 truncatewords_html … … 1793 1801 WITHOUT opening and closing <ul> tags. 1794 1802 1795 **Changed in Django development version** 1796 1797 The format accepted by ``unordered_list`` has changed to an easier to 1798 understand format. 1803 **New in Django development version:** The format accepted by 1804 ``unordered_list`` has changed to be easier to understand. 1799 1805 1800 1806 The list is assumed to be in the proper format. For example, if ``var`` contains … … 1826 1832 {{ value|upper }} 1827 1833 1828 If ``value`` is `` Joel is a slug``, the output would be ``JOEL IS A SLUG``.1834 If ``value`` is ``"Joel is a slug"``, the output will be ``"JOEL IS A SLUG"``. 1829 1835 1830 1836 urlencode … … 1845 1851 {{ value|urlize }} 1846 1852 1847 If ``value`` is `` Check out www.djangoproject.com``, the output wouldbe1848 `` Check out <a1849 href="http://www.djangoproject.com">www.djangoproject.com</a> ``.1853 If ``value`` is ``"Check out www.djangoproject.com"``, the output will be 1854 ``"Check out <a 1855 href="http://www.djangoproject.com">www.djangoproject.com</a>"``. 1850 1856 1851 1857 urlizetrunc … … 1863 1869 {{ value|urlizetrunc:15 }} 1864 1870 1865 If ``value`` is `` Check out www.djangoproject.com``, the output would be1866 `` Check out <a1867 href="http://www.djangoproject.com">www.djangopr...</a> ``.1871 If ``value`` is ``"Check out www.djangoproject.com"``, the output would be 1872 ``'Check out <a 1873 href="http://www.djangoproject.com">www.djangopr...</a>'``. 1868 1874 1869 1875 wordcount
