- Introduction
- Requirements
- Installation
- Usage
- License
This repo contains my custom twig extension. In here you'll find a few native php functions added to twig as a twig extension. Things like creating a random number or using json_decode can now be done directly in Twig.
- Twig ^1.25
- Require the repo with composer
composer require crecket/custom-twig-extension
- Add the extension to the twig view (custom_twig_extension is the class)
$twig = new Twig_Environment();
$twig->addExtension(new custom_twig_extension());
- Download the source
- Require the file
- Add the extension to the twig view
Using these functions and filters is the same as the native functions and filters.
Quick example:
- print_r()
{{ print_r(array) }}
- json_decode
{{ some_variable|json_decode }}
- dumpPre(var1, var2, var3 ...)
- md5(password)
- password_hash(password)
- phpinfo()
- print_r(array)
- pseudoBytes(length)
- randomHex(length)
- randomInt(length)
- randomString(length)
- unsetSession(key)
- wordwrap(string, length, limiter = "\n", cut)
- json_decode
- urlDecode
- sessionVars //Returns all php SESSION variables in array form