BEAR.Sunday Module
PHP HTML
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
.gitignore
.php_cs
.travis.yml
README.md
composer.json
phpcs.xml
phpmd.xml
phpunit.xml

README.md

Madapaja.TwigModule

Twig Module for BEAR.Resource

Latest Stable Version Scrutinizer Code Quality Build Status

Introduction

Madapaja.TwigModule is Twig adaptor extension for BEAR.Sunday framework.

Installation

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": "~1.0"
    }
}

Usage

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.

Resource/Page/Index.html.twig

<h1>{{ greeting }}</h1>

Run your app, enjoy!