PHP code example of cviebrock / twig-group

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

    

cviebrock / twig-group example snippets


$twig = new Twig_Environment($loader, $options);
$twig->addExtension(new Cviebrock\Twig\GroupExtension());

'enabled' => [
	...
	'Cviebrock\Twig\GroupExtension',
],
twig
{{ array | group(2) }}          // [ ['John', 'Jane', 'Bill'], ['Bob', 'Mary'] ]

{{ array | group(3) }}          // [ ['John', 'Jane'], ['Bill', 'Bob'], ['Mary'] ]
twig
{{ array | group(2, '-empty-') }}          // [ ['John', 'Jane', 'Bill'], ['Bob', 'Mary', '-empty-'] ]

{{ array | group(3, '-empty-') }}          // [ ['John', 'Jane'], ['Bill', 'Bob'], ['Mary', '-empty-'] ]