Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 2.12 KB

README.md

File metadata and controls

80 lines (59 loc) · 2.12 KB

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

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!