Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cedricziel/twig-loader-flysystem

Flysystem loader for the twig templating engine
https://github.com/cedricziel/twig-loader-flysystem

flysystem twig

Last synced: 13 days ago
JSON representation

Flysystem loader for the twig templating engine

Awesome Lists containing this project

README

        

# Twig loader for flysystem filesystems

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/cedricziel/twig-loader-flysystem/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/cedricziel/twig-loader-flysystem/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/cedricziel/twig-loader-flysystem/badges/build.png?b=master)](https://scrutinizer-ci.com/g/cedricziel/twig-loader-flysystem/build-status/master)

[Flysystem](http://flysystem.thephpleague.com/) loader for the [Twig](http://twig.sensiolabs.org/) templating engine.

## Installation

The library is installable through composer:

```bash
composer require cedricziel/twig-loader-flysystem
```

## Usage

Adapted from the [official Twig documentation](http://twig.sensiolabs.org/doc/api.html#basics)

```php
$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:

```php
$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