PHP code example of dzango / twig-truncate-extension

1. Go to this page and download the library: Download dzango/twig-truncate-extension 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/ */

    

dzango / twig-truncate-extension example snippets



use Dzango\Twig\Extension\Truncate;

$twig = new Twig_Environment(...);

$twig->addExtension(new Truncate());

truncate($length = 100, $ending = '...', $exact = false, $considerHtml = true)
twig
{{ "some ... very ... large ... text"|truncate }}