diff -r 22a4de35d374 django/trunk/docs/ref/templates/builtins.txt
a
|
b
|
|
1017 | 1017 | |
1018 | 1018 | Adds slashes before quotes. Useful for escaping strings in CSV, for example. |
1019 | 1019 | |
| 1020 | For example:: |
| 1021 | |
| 1022 | {{ value|addslashes }} |
| 1023 | |
| 1024 | If ``value`` is ``"I'm using Django"``, the output will be ``"I\'m using Django"``. |
| 1025 | |
1020 | 1026 | .. templatefilter:: capfirst |
1021 | 1027 | |
1022 | 1028 | capfirst |
… |
… |
|
1024 | 1030 | |
1025 | 1031 | Capitalizes the first character of the value. |
1026 | 1032 | |
| 1033 | For example:: |
| 1034 | |
| 1035 | {{ value|capfirst }} |
| 1036 | |
| 1037 | If ``value`` is ``"django"``, the output will be ``"Django"``. |
| 1038 | |
1027 | 1039 | .. templatefilter:: center |
1028 | 1040 | |
1029 | 1041 | center |
… |
… |
|
1031 | 1043 | |
1032 | 1044 | Centers the value in a field of a given width. |
1033 | 1045 | |
| 1046 | For example:: |
| 1047 | |
| 1048 | "{{ value|center:"15" }}" |
| 1049 | |
| 1050 | If ``value`` is ``"Django"``, the output will be ``" Django "``. |
| 1051 | |
1034 | 1052 | .. templatefilter:: cut |
1035 | 1053 | |
1036 | 1054 | cut |
… |
… |
|
1194 | 1212 | string safe for use in HTML, but does protect you from syntax errors when using |
1195 | 1213 | templates to generate JavaScript/JSON. |
1196 | 1214 | |
| 1215 | For example:: |
| 1216 | |
| 1217 | {{ value|escapejs }} |
| 1218 | |
| 1219 | If ``value`` is ``"testing\r\njavascript \'string" <b>escaping</b>"``, |
| 1220 | the output will be ``"testing\\x0D\\x0Ajavascript \\x27string\\x22 \\x3Cb\\x3Eescaping\\x3C/b\\x3E"``. |
| 1221 | |
1197 | 1222 | .. templatefilter:: filesizeformat |
1198 | 1223 | |
1199 | 1224 | filesizeformat |
… |
… |
|
1320 | 1345 | It's safe to use this filter on a string that has already gone through the |
1321 | 1346 | ``urlencode`` filter. |
1322 | 1347 | |
| 1348 | For example:: |
| 1349 | |
| 1350 | {{ value|iriencode }} |
| 1351 | |
| 1352 | If ``value`` is ``"?test=1&me=2"``, the output will be ``"?test=1&me=2"``. |
| 1353 | |
1323 | 1354 | .. templatefilter:: join |
1324 | 1355 | |
1325 | 1356 | join |
… |
… |
|
1400 | 1431 | Converts all newlines in a piece of plain text to HTML line breaks |
1401 | 1432 | (``<br />``). |
1402 | 1433 | |
| 1434 | For example:: |
| 1435 | |
| 1436 | {{ value|linebreaksbr }} |
| 1437 | |
| 1438 | If ``value`` is ``Joel\nis a slug``, the output will be ``Joel<br />is a |
| 1439 | slug``. |
| 1440 | |
1403 | 1441 | .. templatefilter:: linenumbers |
1404 | 1442 | |
1405 | 1443 | linenumbers |
… |
… |
|
1407 | 1445 | |
1408 | 1446 | Displays text with line numbers. |
1409 | 1447 | |
| 1448 | For example:: |
| 1449 | |
| 1450 | {{ value|linenumbers }} |
| 1451 | |
| 1452 | If ``value`` is:: |
| 1453 | |
| 1454 | one |
| 1455 | two |
| 1456 | three |
| 1457 | |
| 1458 | the output will be:: |
| 1459 | |
| 1460 | 1. one |
| 1461 | 2. two |
| 1462 | 3. three |
| 1463 | |
1410 | 1464 | .. templatefilter:: ljust |
1411 | 1465 | |
1412 | 1466 | ljust |
… |
… |
|
1416 | 1470 | |
1417 | 1471 | **Argument:** field size |
1418 | 1472 | |
| 1473 | For example:: |
| 1474 | |
| 1475 | "{{ value|ljust:"10" }}" |
| 1476 | |
| 1477 | If ``value`` is ``Django``, the output will be ``"Django "``. |
| 1478 | |
1419 | 1479 | .. templatefilter:: lower |
1420 | 1480 | |
1421 | 1481 | lower |
… |
… |
|
1451 | 1511 | ~~~~~~~~~~~~~ |
1452 | 1512 | |
1453 | 1513 | Converts a phone number (possibly containing letters) to its numerical |
1454 | | equivalent. For example, ``'800-COLLECT'`` will be converted to |
1455 | | ``'800-2655328'``. |
| 1514 | equivalent. |
1456 | 1515 | |
1457 | 1516 | The input doesn't have to be a valid phone number. This will happily convert |
1458 | 1517 | any string. |
1459 | 1518 | |
| 1519 | For example:: |
| 1520 | |
| 1521 | {{ value|phone2numeric }} |
| 1522 | |
| 1523 | If ``value`` is ``800-COLLECT``, the output will be ``800-2655328``. |
| 1524 | |
1460 | 1525 | .. templatefilter:: pluralize |
1461 | 1526 | |
1462 | 1527 | pluralize |
… |
… |
|
1468 | 1533 | |
1469 | 1534 | You have {{ num_messages }} message{{ num_messages|pluralize }}. |
1470 | 1535 | |
| 1536 | If ``num_messages`` is ``1``, the output will be ``You have 1 message.`` |
| 1537 | If ``num_messages`` is ``2`` the output will be ``You have 2 messages.`` |
| 1538 | |
1471 | 1539 | For words that require a suffix other than ``'s'``, you can provide an alternate |
1472 | 1540 | suffix as a parameter to the filter. |
1473 | 1541 | |
… |
… |
|
1527 | 1595 | |
1528 | 1596 | **Argument:** field size |
1529 | 1597 | |
| 1598 | For example:: |
| 1599 | |
| 1600 | "{{ value|rjust:"10" }}" |
| 1601 | |
| 1602 | If ``value`` is ``Django``, the output will be ``" Django"``. |
| 1603 | |
1530 | 1604 | .. templatefilter:: safe |
1531 | 1605 | |
1532 | 1606 | safe |
… |
… |
|
1565 | 1639 | |
1566 | 1640 | {{ some_list|slice:":2" }} |
1567 | 1641 | |
| 1642 | If ``some_list`` is ``['a', 'b', 'c']``, the output will be ``['a', 'b']``. |
| 1643 | |
1568 | 1644 | .. templatefilter:: slugify |
1569 | 1645 | |
1570 | 1646 | slugify |
… |
… |
|
1684 | 1760 | |
1685 | 1761 | Converts a string into titlecase. |
1686 | 1762 | |
| 1763 | For example:: |
| 1764 | |
| 1765 | {{ value|title }} |
| 1766 | |
| 1767 | If ``value`` is ``"my first post"``, the output will be ``"My First Post"``. |
| 1768 | |
1687 | 1769 | .. templatefilter:: truncatewords |
1688 | 1770 | |
1689 | 1771 | truncatewords |
… |
… |
|
1711 | 1793 | This is less efficient than ``truncatewords``, so should only be used when it |
1712 | 1794 | is being passed HTML text. |
1713 | 1795 | |
| 1796 | For example:: |
| 1797 | |
| 1798 | {{ value|truncatewords_html:2 }} |
| 1799 | |
| 1800 | If ``value`` is ``"<p>Joel is a slug</p>"``, the output will be |
| 1801 | ``"<p>Joel is ...</p>"``. |
| 1802 | |
1714 | 1803 | .. templatefilter:: unordered_list |
1715 | 1804 | |
1716 | 1805 | unordered_list |
… |
… |
|
1761 | 1850 | |
1762 | 1851 | Escapes a value for use in a URL. |
1763 | 1852 | |
| 1853 | For example:: |
| 1854 | |
| 1855 | {{ value|urlencode }} |
| 1856 | |
| 1857 | If ``value`` is ``"http://www.example.org/foo?a=b&c=d"``, the output will be |
| 1858 | ``"http%3A//www.example.org/foo%3Fa%3Db%26c%3Dd"``. |
| 1859 | |
1764 | 1860 | .. templatefilter:: urlize |
1765 | 1861 | |
1766 | 1862 | urlize |
… |
… |
|
1806 | 1902 | |
1807 | 1903 | Returns the number of words. |
1808 | 1904 | |
| 1905 | For example:: |
| 1906 | |
| 1907 | {{ value|wordcount }} |
| 1908 | |
| 1909 | If ``value`` is ``"Joel is a slug"``, the output will be ``4``. |
| 1910 | |
1809 | 1911 | .. templatefilter:: wordwrap |
1810 | 1912 | |
1811 | 1913 | wordwrap |