crecket / custom-twig-extension
My custom twig extension
2.2
2016-04-17 10:48 UTC
Requires
- twig/twig: ^1.23
README
Content
- Introduction
- Requirements
- Installation
- Usage
- License
Introduction
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.
Requirements
- Twig ^1.25
Installation
Composer
- 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());
Manual
- Download the source
- Require the file
- Add the extension to the twig view
Usage
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 }}
List
Functions
- 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)
Filters
- json_decode
- urlDecode
Globals
- sessionVars //Returns all php SESSION variables in array form