Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

minor #128 Added documentation for wordwrap and truncate filter (drit…

…ter)

This PR was squashed before being merged into the 1.2.x-dev branch (closes #128).

Discussion
----------

Added documentation for wordwrap and truncate filter

As requested in #86, here is some documentation for wordwrap and truncate.

Commits
-------

33eb901 Added documentation for wordwrap and truncate filter
commit a155ec01555ffa3aab3e7e042d55aab549c83b75 2 parents 69ca523 + 33eb901
@fabpot fabpot authored
Showing with 61 additions and 0 deletions.
  1. +61 −0 doc/text.rst
View
61 doc/text.rst
@@ -13,3 +13,64 @@ First, :ref:`install the Extensions library<extensions-install>`. Next, add
the extension to Twig::
$twig->addExtension(new Twig_Extensions_Extension_Text());
+
+Wrapping Words
+--------------
+
+Use the ``wordwrap`` filter to split your text in lines with equal length.
+
+.. code-block:: jinja
+
+ {{ "Lorem ipsum dolor sit amet, consectetur adipiscing" | wordwrap(10) }}
+
+This example would print::
+
+ Lorem ipsu
+ m dolor si
+ t amet, co
+ nsectetur
+ adipiscing
+
+The default separator is "\\n", but you can easily change that by providing one:
+
+.. code-block:: jinja
+
+ {{ "Lorem ipsum dolor sit amet, consectetur adipiscing" | wordwrap(10, "zz\n") }}
+
+This would result in::
+
+ Lorem ipsuzz
+ m dolor sizz
+ t amet, cozz
+ nsectetur zz
+ adipiscing
+
+Truncating Text
+---------------
+
+Use the ``truncate`` filter to cut off a string after limit is reached
+
+.. code-block:: jinja
+
+ {{ "Hello World!" | truncate(5) }}
+
+The example would output ``Hello...``, as ``...`` is the default separator.
+
+You can also tell truncate to preserve whole words by setting the second
+parameter to ``true``. If the last Word is on the the separator, truncate
+will print out the whole Word.
+
+.. code-block:: jinja
+
+ {{ "Hello World!" | truncate(7, true) }}
+
+Here ``Hello World!`` would be printed.
+
+If you want to change the separator, just set the third parameter to
+your desired separator.
+
+.. code-block:: jinja
+
+ {{ "Hello World!" | truncate(7, false, "??") }}
+
+This example would print ``Hello W??``.
Please sign in to comment.
Something went wrong with that request. Please try again.