PHP code example of falc / twig-text-extension

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

    

falc / twig-text-extension example snippets


$twig = new Twig_Environment($loader, $options);
$twig->addExtension(new Falc\Twig\Extension\TextExtension());

// Example
{{ '<p>First paragraph.</p><p>Second paragraph.</p><p>Third paragraph</p>' | paragraphs_slice }}

// Output
["<p>First paragraph.</p>", "<p>Second paragraph.</p>", "<p>Third paragraph</p>"]

// Example
{{ '<p>First paragraph.</p><p>Second paragraph.</p><p>Third paragraph</p>' | paragraphs_slice(0, 2) }}

// Output
["<p>First paragraph.</p>", "<p>Second paragraph.</p>"]

// Example
{{ '<p>First paragraph.</p><p>Second paragraph.</p><p>Third paragraph</p>' | paragraphs_slice(1, 1) }}

// Output
["<p>Second paragraph.</p>"]

// Example
{{ '<p>First paragraph.</p><p>Second paragraph.</p><p>Third paragraph</p>' | paragraphs_slice(0, 2) | join }}

// Output
"<p>First paragraph.</p><p>Second paragraph.</p>"

{{ '<p>First paragraph.</p><p>Second paragraph.</p><p>Third paragraph</p>' | paragraphs_slice(0, 2) | join | raw }}