ZF2: Twig Templateengine installieren und aktivieren

Notizen zur Installation von Twig unter Zend 2.

Composer Beispielkonfiguration:

{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.3.*",
        "zendframework/zftool": "dev-master",
        "zf-commons/zfc-twig": "dev-master",
        "zendframework/zend-modulemanager": "2.3.*@dev"
    }
}

Mit Composer  installieren:

composer require zf-commons/zfc-twig:dev-master

Twig Modul in application.config.php aktivieren:

<?php
/**
 * Configuration file generated by ZFTool
 * The previous configuration file is stored in application.config.old
 *
 * @see https://github.com/zendframework/ZFTool
 */
return array(
    'modules' => array(
        'Application',
		'ZfcTwig'
    ),
    'module_listener_options' => array(
        'module_paths' => array(
            './module',
            './vendor'
        ),
        'config_glob_paths' => array(
            'config/autoload/{,*.}{global,local}.php'
        )
    )
);

Die Twig Example Templates ersetzen dann die Templates der ZF2 Skeleton Application.

Zu finden sind diese unter:

vendor/zf-commons/zfc-twig/examples

und ersetzen die Templates in diesem Ordner:

module/Application/view