PHP code example of jasny / twig-extensions

1. Go to this page and download the library: Download jasny/twig-extensions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jasny / twig-extensions example snippets


$twig = new Twig_Environment($loader, $options);
$twig->addExtension(new Jasny\Twig\DateExtension());
$twig->addExtension(new Jasny\Twig\PcreExtension());
$twig->addExtension(new Jasny\Twig\TextExtension());
$twig->addExtension(new Jasny\Twig\ArrayExtension());

Locale::setDefault(LC_ALL, "en_US"); // vs "nl_NL"

{{"now"|localdate('long')}}                 <!-- July 12, 2013 --> <!-- 12 juli 2013 -->
{{"now"|localtime('short')}}                <!-- 5:53 PM --> <!-- 17:53 -->
{{"2013-10-01 23:15:00"|localdatetime}}     <!-- 10/01/2013 11:15 PM --> <!-- 01-10-2013 23:15 -->
{{"22-08-1981"|age}}                        <!-- 35 -->
{{ 3600|duration }}                         <!-- 1h -->