Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Jan 19, 2018
1 parent 792453d commit 584b7b2
Showing 1 changed file with 3 additions and 120 deletions.
123 changes: 3 additions & 120 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,128 +1,11 @@
# Madapaja.TwigModule

Madapaja.TwigModule is [Twig](http://twig.sensiolabs.org/) **v2** adaptor extension for [BEAR.Sunday](https://github.com/koriym/BEAR.Sunday) framework.
Madapaja.TwigModule is [Twig](http://twig.sensiolabs.org/) v2 module for [BEAR.Sunday](https://github.com/koriym/BEAR.Sunday) framework.

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/madapaja/Madapaja.TwigModule/badges/quality-score.png?b=2.x)](https://scrutinizer-ci.com/g/madapaja/Madapaja.TwigModule/?branch=2.x)
[![Code Coverage](https://scrutinizer-ci.com/g/madapaja/Madapaja.TwigModule/badges/coverage.png?b=2.x)](https://scrutinizer-ci.com/g/madapaja/Madapaja.TwigModule/?branch=2.x)
[![Build Status](https://travis-ci.org/madapaja/Madapaja.TwigModule.svg)](https://travis-ci.org/madapaja/Madapaja.TwigModule)

# Installation
# Documentation

## Composer install

```
composer require madapaja/twig-module 2.x-dev
```

## Module Install

```php
namespace MyVendor\MyPackage\Module;

use Ray\Di\AbstractModule;

class HtmlModule extends AbstractModule
{
protected function configure()
{
$this->install(new TwigModule);
}
}
```

Place twig template file in the same directory of resource class or `var/templates/` directory.

```twig
<h1>{{ greeting }}</h1>
```

`_ro` is automatically assigned as target resoure.

```twig
{{ _ro.code }} // resouce code
{{ _ro.header.content-type }} // header
{% for todo in _ro.body %} // body
{{ todo.title }}
{% endfor %}
```

For example, The template file for `Resource/Page/Index` class should be place either

* `src/Resource/Page/Index.html.twig`

or

* `var/templates/Page/Index.html.twig`

## Extending Twig

You may want to extend twig with `addExtension()` method.
In that case, provide your own Twig Provider class.

```php
use Ray\Di\Di\Named;
use Ray\Di\ProviderInterface;

class MyTwigEnvironmentProvider implements ProviderInterface
{
private $twig;

/**
* @Named("original")
*/
public function __construct(\Twig_Environment $twig)
{
// $twig is an original \Twig_Environment instance
$this->twig = $twig;
}

public function get()
{
// Extending Twig
$this->twig->addExtension(new MyTwigExtension());

return $this->twig;
}
}
```

And bind it to `Twig_Environment` class.

```php
class HtmlModule extends AbstractModule
{
protected function configure()
{
$this->install(new TwigModule());

// override \Twig_Environment provider
$this
->bind(\Twig_Environment::class)
->toProvider(MyTwigEnvironmentProvider::class)
->in(Scope::SINGLETON);
}
}
```

## Options

You may want to specify custom path or options for Twig template engine.

```php
class HtmlModule extends AbstractModule
{
protected function configure()
{
$appDir = dirname(dirname(__DIR__));
$paths = [
$appDir . '/src/Resource',
$appDir . '/var/templates'
];
$options = [
'debug' => true,
'cache' => $appDir . '/tmp/twig'
];
$this->install(new TwigModule($paths, $options));
}
}
```
The documentation is available in [English](http://bearsunday.github.io/manuals/1.0/en/html-v2.html) or [Japanese](http://bearsunday.github.io/manuals/1.0/ja/html-v2.html).

0 comments on commit 584b7b2

Please sign in to comment.