Download the PHP package falc/twig-text-extension without Composer
On this page you can find all versions of the php package falc/twig-text-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package twig-text-extension
Twig Text Extension
TwigTextExtension contains the following filters:
br2p
: Replaces double linebreaks formatting into paragraphs.hash
: Exposes the hash function included in PHP.p2br
: Replaces paragraph formatting with double linebreaks.paragraphs_slice
: Extracts paragraphs from a string. Similar to array_slice.regex_replace
: Exposes the preg_replace function included in PHP.repeat
: Exposes the str_repeat function included in PHP.
License: MIT
Requirements
- Twig >= 1.12
Installation
Add the falc/twig-text-extension
package to your composer.json
:
Symfony
To use it in a Symfony project you have to register the extension as a service.
If there is already an extension registered as twig.extension.text
you can give the new one a different name:
Other
To use it in other projects:
Usage
br2p
hash(algorithm, rawOutput)
algorithm
: Name of selected hashing algorithm (i.e. "md5", "sha256", "haval160,4", etc..)rawOutput
: When set totrue
, outputs raw binary data.False
outputs lowercase hexits.- Optional.
- Default is false.
Check hash_algos()
to find a list of available algorithms.
p2br
paragraphs_slice(offset, length)
offset
: Number of paragraphs to offset.- Optional.
- Default is 0.
length
: Number of paragraphs to return.- Optional.
- Default is null.
This filter works like array_slice.
Examples
Without parameters, it will return an array containing all the paragraphs:
Return an array containing the first two paragraphs:
Return an array containing only the second paragraph:
Return an array containing the last paragraph:
Twig allows to chain filters, so you can join the resulting array using join...
...and to make Twig process HTML, chain the raw filter:
That way it is possible to truncate a text at a paragraph level.
regex_replace(pattern, replacement, limit)
pattern
: Pattern to search for. It can be either a string or an array with strings.replacement
: String or array with strings to replace.limit
: Maximum possible replacements for each pattern in each subject string.- Optional.
- Default is -1 (no limit).
repeat(num)
num
: Number of times to repeat the string.