cedricziel/twig-loader-flysystem

Flysystem loader for the twig templating language

v1.1.0 2016-08-25 16:39 UTC

This package is auto-updated.

Last update: 2024-03-28 09:49:58 UTC


README

Scrutinizer Code Quality Build Status

Flysystem loader for the Twig templating engine.

Installation

The library is installable through composer:

composer require cedricziel/twig-loader-flysystem

Usage

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'));

License

MIT