appt/twig

There is no license information available for the latest version (1.0.0) of this package.

Integrate Twig with ZF2.

1.0.0 2013-03-18 00:56 UTC

This package is auto-updated.

Last update: 2024-03-07 15:16:52 UTC


README

Integrate Twig with ZF2.

Build Status

Install

Using composer

Add following in your composer.json:

{
    "require": {
        "appt/twig": "1.*"
    }
}

And enable module in your application.config.php:

return array(
    'modules' => array(
        'ApptTwig',
    )
);

Usage

Configuration
Templates

ApptTwig support adding templates using common for Zend Framework 2 TemplateMapResolver and TemplatePathStack loaders.

return array(
    'appt' => array(
        'twig' => array(
            'default_template_suffix' => 'twg', // you can change file extension used by TemplatePathStack
            'template_path_stack' => array(
                'dir/1/',
                'dir/2/'
            ),
            'template_map' => array(
                'layout/layout' => 'dir/layout.twig',
                'error' => __DIR__ . 'dir/error.twig',
            ),
        ),
    ),
);
Twig options

You can change twig engine option in config:

return array(
 'appt' => array(
        'twig' => array(
            'engine_options' => array(
                'debug' => true, // turn on debug mode
            )
        ),
    ),
);
Twig extensions

Also it is possible to add new twig extensions:

return array(
    'appt' => array(
        'twig' => array(
            'extension_manager' => array(
                'factories' => array (
                    'ZendViewHelpers' => 'ApptTwig\Service\Extension\ZendViewHelpersFactory'
                )
            ),
        )
    )
);

All extensions must implement Twig_ExtensionInterface.

Provided services

ApptTwig provide following services:

appt.twig.renderer -- renderer service compatible with PhpRenderer; appt.twig.renderer_strategy -- renderer strategy;
appt.twig.resolver -- resolver service extend Zend\View\Resolver\AggregateResolver and used for resolving templates; appt.twig.extension_manager -- used for managing twig extensions, it extend Zend\ServiceManager\AbstractPluginManager.

Rendering

When you setup resolvers in your config ApptTwig is ready for rendering view templates as it was regular PhpRenderer. All you need is create templates in your view directory.