Flysystem loader for the Twig templating engine.
The library is installable through composer:
composer require cedricziel/twig-loader-flysystem
Adapted from the official Twig documentation
$localAdapter = new League\Flysystem\Adapter\Local(__DIR__);
$filesystem = League\Flysystem\Filesystem($localAdapter);
$loader = new CedricZiel\TwigLoaderFlysystem\FlysystemLoader($filesystem);
$twig = new \Twig_Environment($loader);
$template = $twig->loadTemplate('index.html.twig');
$content = $template->render(array('the' => 'variables', 'go' => 'here'));
The loader also supports using a subdirectory on the associated flysystem as permanent prefix:
$localAdapter = new League\Flysystem\Adapter\Local(__DIR__);
$filesystem = League\Flysystem\Filesystem($localAdapter);
$loader = new CedricZiel\TwigLoaderFlysystem\FlysystemLoader($filesystem, 'templates');
$twig = new \Twig_Environment($loader);
// this will load 'templates/index.html.twig' from the current flysystem filesystem
$template = $twig->loadTemplate('index.html.twig');
$content = $template->render(array('the' => 'variables', 'go' => 'here'));
MIT