Download the PHP package amberovsky/zf2-twig without Composer
On this page you can find all versions of the php package amberovsky/zf2-twig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amberovsky/zf2-twig
More information about amberovsky/zf2-twig
Files in amberovsky/zf2-twig
Package zf2-twig
Short Description Zend Framework 2 Module that provides a Twig rendering strategy and extensions to render actions or trigger events from your templates
License
Homepage https://github.com/amberovsky/zf2-twig/
Informations about the package zf2-twig
ZfcTwig Module for Zend Framework 2
ZfcTwig is a module that integrates the Twig templating engine with Zend Framework 2.
Installation
- Add
"amberovsky/zf2-twig": "dev-master"
to yourcomposer.json
file and runphp composer.phar update
. - Add
ZfcTwig
to yourconfig/application.config.php
file under themodules
key.
Configuration
ZfcTwig has sane defaults out of the box but offers optional configuration via the zfctwig
configuration key. For
detailed information on all available options see the module config file
class.
Documentation
Setting up Twig extensions
Extensions can be registered with Twig by adding the FQCN to the extensions
configuration key which is exactly how the
ZfcTwig extension is registered.
Configuring Twig loaders
By default, ZfcTwig uses a Twig_Loader_Chain so that loaders can be chained together. A convenient default is setup using
a filesystem loader with the path set to
module/Application/view
which should work out of the box for most instances. If you wish to add additional loaders
to the chain you can register them by adding the service manager alias to the loaders
configuration key.
Using ZF2 View Helpers
Using ZF2 view helpers is supported through the ZfcTwig\Twig\FallbackFunction function.
Examples
Example .twig files for the skeleton application can be found in the examples folder.
Gotchas
ZF2 does not support multiple renderers with view helpers very well. As a workaround, ZfcTwig registers its own
HelperPluginManager
that extends the default Zend\View\HelperPluginManager
and adds the default as a peering manager.
This let's ZfcTwig register its own renderer with view helpers that require it and fallback to the default manager for
view helpers that do not require one.
As a caveat, you must register view helpers that require a renderer with ZfcTwig. An example can be seen in
config/module.config.php
where the HelperConfig for the default navigation helpers is registered with ZfcTwig.