Ticket #12496: django_build-in_filter_examples.2.diff

File django_build-in_filter_examples.2.diff, 4.6 KB (added by Arthur Koziel, 14 years ago)

fixed ljust/rjust examples

  • django/trunk/docs/ref/templates/builtins.txt

    diff -r 22a4de35d374 django/trunk/docs/ref/templates/builtins.txt
    a b  
    10171017
    10181018Adds slashes before quotes. Useful for escaping strings in CSV, for example.
    10191019
     1020For example::
     1021
     1022    {{ value|addslashes }}
     1023
     1024If ``value`` is ``"I'm using Django"``, the output will be ``"I\'m using Django"``.
     1025
    10201026.. templatefilter:: capfirst
    10211027
    10221028capfirst
     
    10241030
    10251031Capitalizes the first character of the value.
    10261032
     1033For example::
     1034
     1035    {{ value|capfirst }}
     1036
     1037If ``value`` is ``"django"``, the output will be ``"Django"``.
     1038
    10271039.. templatefilter:: center
    10281040
    10291041center
     
    10311043
    10321044Centers the value in a field of a given width.
    10331045
     1046For example::
     1047
     1048    "{{ value|center:"15" }}"
     1049
     1050If ``value`` is ``"Django"``, the output will be ``"     Django    "``.
     1051
    10341052.. templatefilter:: cut
    10351053
    10361054cut
     
    11941212string safe for use in HTML, but does protect you from syntax errors when using
    11951213templates to generate JavaScript/JSON.
    11961214
     1215For example::
     1216
     1217    {{ value|escapejs }}
     1218
     1219If ``value`` is ``"testing\r\njavascript \'string" <b>escaping</b>"``,
     1220the output will be ``"testing\\x0D\\x0Ajavascript \\x27string\\x22 \\x3Cb\\x3Eescaping\\x3C/b\\x3E"``.
     1221
    11971222.. templatefilter:: filesizeformat
    11981223
    11991224filesizeformat
     
    13201345It's safe to use this filter on a string that has already gone through the
    13211346``urlencode`` filter.
    13221347
     1348For example::
     1349
     1350    {{ value|iriencode }}
     1351
     1352If ``value`` is ``"?test=1&me=2"``, the output will be ``"?test=1&amp;me=2"``.
     1353
    13231354.. templatefilter:: join
    13241355
    13251356join
     
    14001431Converts all newlines in a piece of plain text to HTML line breaks
    14011432(``<br />``).
    14021433
     1434For example::
     1435
     1436    {{ value|linebreaksbr }}
     1437
     1438If ``value`` is ``Joel\nis a slug``, the output will be ``Joel<br />is a
     1439slug``.
     1440
    14031441.. templatefilter:: linenumbers
    14041442
    14051443linenumbers
     
    14071445
    14081446Displays text with line numbers.
    14091447
     1448For example::
     1449
     1450    {{ value|linenumbers }}
     1451
     1452If ``value`` is::
     1453
     1454    one
     1455    two
     1456    three
     1457
     1458the output will be::
     1459
     1460    1. one
     1461    2. two
     1462    3. three
     1463
    14101464.. templatefilter:: ljust
    14111465
    14121466ljust
     
    14161470
    14171471**Argument:** field size
    14181472
     1473For example::
     1474
     1475    "{{ value|ljust:"10" }}"
     1476
     1477If ``value`` is ``Django``, the output will be ``"Django    "``.
     1478
    14191479.. templatefilter:: lower
    14201480
    14211481lower
     
    14511511~~~~~~~~~~~~~
    14521512
    14531513Converts a phone number (possibly containing letters) to its numerical
    1454 equivalent. For example, ``'800-COLLECT'`` will be converted to
    1455 ``'800-2655328'``.
     1514equivalent.
    14561515
    14571516The input doesn't have to be a valid phone number. This will happily convert
    14581517any string.
    14591518
     1519For example::
     1520
     1521    {{ value|phone2numeric }}
     1522
     1523If ``value`` is ``800-COLLECT``, the output will be ``800-2655328``.
     1524
    14601525.. templatefilter:: pluralize
    14611526
    14621527pluralize
     
    14681533
    14691534    You have {{ num_messages }} message{{ num_messages|pluralize }}.
    14701535
     1536If ``num_messages`` is ``1``, the output will be ``You have 1 message.``
     1537If ``num_messages`` is ``2``  the output will be ``You have 2 messages.``
     1538
    14711539For words that require a suffix other than ``'s'``, you can provide an alternate
    14721540suffix as a parameter to the filter.
    14731541
     
    15271595
    15281596**Argument:** field size
    15291597
     1598For example::
     1599
     1600    "{{ value|rjust:"10" }}"
     1601
     1602If ``value`` is ``Django``, the output will be ``"    Django"``.
     1603
    15301604.. templatefilter:: safe
    15311605
    15321606safe
     
    15651639
    15661640    {{ some_list|slice:":2" }}
    15671641
     1642If ``some_list`` is ``['a', 'b', 'c']``, the output will be ``['a', 'b']``.
     1643
    15681644.. templatefilter:: slugify
    15691645
    15701646slugify
     
    16841760
    16851761Converts a string into titlecase.
    16861762
     1763For example::
     1764
     1765    {{ value|title }}
     1766
     1767If ``value`` is ``"my first post"``, the output will be ``"My First Post"``.
     1768
    16871769.. templatefilter:: truncatewords
    16881770
    16891771truncatewords
     
    17111793This is less efficient than ``truncatewords``, so should only be used when it
    17121794is being passed HTML text.
    17131795
     1796For example::
     1797
     1798    {{ value|truncatewords_html:2 }}
     1799
     1800If ``value`` is ``"<p>Joel is a slug</p>"``, the output will be
     1801``"<p>Joel is ...</p>"``.
     1802
    17141803.. templatefilter:: unordered_list
    17151804
    17161805unordered_list
     
    17611850
    17621851Escapes a value for use in a URL.
    17631852
     1853For example::
     1854
     1855    {{ value|urlencode }}
     1856
     1857If ``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
    17641860.. templatefilter:: urlize
    17651861
    17661862urlize
     
    18061902
    18071903Returns the number of words.
    18081904
     1905For example::
     1906
     1907    {{ value|wordcount }}
     1908
     1909If ``value`` is ``"Joel is a slug"``, the output will be ``4``.
     1910
    18091911.. templatefilter:: wordwrap
    18101912
    18111913wordwrap
Back to Top