PHP code example of elazar / flysystem-twig-loader
1. Go to this page and download the library: Download elazar/flysystem-twig-loader 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/ */
elazar / flysystem-twig-loader example snippets
/**
* 1. Instantiate the Flysystem filesystem reader with an appropriate adapter.
*
* Note: Because the Twig loader only executes read operations, it technically only
* systemAdapter('/path/to/templates');
$filesystemReader = new League\Flysystem\Filesystem($filesystemAdapter);
/**
* 2. Instantiate the Twig template loader and pass the Flysystem filesystem
* reader to it.
*
* @see https://twig.symfony.com/doc/3.x/api.html#loaders
*/
$templateLoader = new Elazar\FlysystemTwigLoader\FlysystemLoader($filesystemReader);
/**
* 3. Instantiate the Twig environment and pass the Twig template loader to it.
*
* @see https://twig.symfony.com/doc/3.x/api.html#basics
*/
$twig = new Twig\Environment($templateLoader);
/**
* 4. Load or render templates as normal with Twig; they will be sourced from
* the Flysystem filesystem object.
*
* @see https://twig.symfony.com/doc/3.x/api.html#loading-templates
* @see https://twig.symfony.com/doc/3.x/api.html#rendering-templates
*/
$path = '/path/to/template.html.twig';
$data = ['the' => 'variables', 'go' => 'here'];
$template = $twig->load($path);
echo $template->render($data);
// or
echo $twig->render($path, $data);