Twig Module for BEAR.Resource
Madapaja.TwigModule is Twig adaptor extension for BEAR.Sunday framework.
Add the package name to your composer.json
.
To composer command:
composer require madapaja/twig-module
or to modify your composer.json
and composer update
command:
{
"require": {
"madapaja/twig-module": "~0.2"
}
}
For example you are using BEAR.Package ...
modifying your AppModule
as:
namespace MyVendor\MyPackage\Module;
use Madapaja\TwigModule\Annotation\TwigOptions;
use Madapaja\TwigModule\Annotation\TwigPaths;
use Madapaja\TwigModule\TwigModule;
use Ray\Di\AbstractModule;
class AppModule extends AbstractModule
{
protected function configure()
{
$this->install(new TwigModule());
// You can add twig template paths by the following
$appDir = dirname(dirname(__DIR__));
$paths = [$appDir . '/src/Resource', $appDir . '/var/lib/twig'];
$this->bind()->annotatedWith(TwigPaths::class)->toInstance($paths);
// Also you can set environment options
// @see http://twig.sensiolabs.org/doc/api.html#environment-options
$options = [
'debug' => true,
'cache' => '/tmp/'
];
$this->bind()->annotatedWith(TwigOptions::class)->toInstance($options);
}
}
And you put twig template file into the resource directory.
<h1>{{ greeting }}</h1>
Run your app, enjoy!