alexmasterov/twig-extension

A collection of custom extensions for the Twig template engine

0.4.0 2016-09-24 23:13 UTC

This package is not auto-updated.

Last update: 2024-11-19 17:31:45 UTC


README

Latest Stable Version License Build Status Code Coverage Scrutinizer Code Quality

A collection of custom extensions for the Twig template engine.

Extensions

Psr7UriExtension — provides useful functions using PSR-7 HTTP message interface.

Installation

The suggested installation method is via composer:

composer require alexmasterov/twig-extension

Configuration

To activate an extension you need to register it into the Twig environment:

/*
* @var $twig    Twig_Environment
* @var $request ServerRequestInterface
*/
$twig->addExtension(
    new AlexMasterov\TwigExtension\Psr7UriExtension(ServerRequestInterface $request)
);

The example of registering the extension using Auryn and Diactoros:

$injector = new Auryn\Injector;
$injector->alias(
    Psr\Http\Message\ServerRequestInterface::class,
    Zend\Diactoros\ServerRequest::class
);

/*
* @var $twig Twig_Environment
*/
$twig->addExtension(
    $injector->make(AlexMasterov\TwigExtension\Psr7UriExtension::class)
);