Skip to content

cedricziel/twig-loader-flysystem

Repository files navigation

Twig loader for flysystem filesystems

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

About

Flysystem loader for the twig templating engine

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages