Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated module to be compatible with beta4 version of ZF2.
- Loading branch information
1 parent
7a4b2c0
commit 85ec6fe
Showing
11 changed files
with
245 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,82 @@ | ||
ZeTwig | ||
==== | ||
|
||
ZeTwig is a Twig / Zend Framework 2 module compatible with ViewModels from beta3. | ||
ZeTwig is a Twig / Zend Framework 2 module compatible the beta4 version of the framework. | ||
It allows to render view templates using Twig instead of the default PHP templates. | ||
It also supports aliases for your template names, rendering a particular action from | ||
within the template files (follows the save naming conventions as Symfony) and | ||
triggering events on an object with different parameters. | ||
|
||
Instalation | ||
----------- | ||
|
||
ZeTwig can be installed using Composer by simply adding the following lines to your composer.json file: | ||
|
||
```json | ||
"require": { | ||
"ZendExperts/ZeTwig": "1.0.*" | ||
} | ||
``` | ||
|
||
Then run `php composer.phar update`. | ||
|
||
The module also defines a set of options that you can change from within the configuration files: | ||
|
||
```php | ||
'zendexperts_zetwig' => array( | ||
//you can change the extension of the loaded templates here | ||
'template_suffix' => 'twig', | ||
'extensions' => array( | ||
//add any extensions you want to register with twig | ||
), | ||
//set twig environment options | ||
'environment_options' => array( | ||
'cache' => BASE_PATH . '/data/cache/twig', | ||
'auto_reload' => true, | ||
'debug' => true | ||
), | ||
), | ||
``` | ||
|
||
Documentation | ||
------------- | ||
|
||
Upgraded to the new beta3 version of ZF2 View Models. | ||
2012.05.25: Upgraded to the beta4 version of ZF2 View Models. | ||
|
||
Any command from the original Twig library should work and also added support for | ||
Zend View helpers as functions and PHP functions as a fallback. | ||
|
||
With this new update you should be able to use template names as aliases that can be | ||
mapped to any twig file. | ||
|
||
You can define an array for aliases within the configuration file for your modules and | ||
use those aliases throughout your code, instead of a specific file name. This way you | ||
can easily change the main layout of your pages from the configuration file and allow | ||
other modules to change them as well (this allows your code to be extensible and allows | ||
templates to have their own structure). | ||
|
||
This latest version also contains two new constructs: | ||
Apart from the functionality listed above the module adds two extension tags: | ||
|
||
1. A tag for rendering a controller action, which follows the Symfony naming conventions | ||
or the controller alias and can be used as : | ||
|
||
1. A tag for rendering a controller action, which follows the Symfony naming conventions | ||
or the controller alias: | ||
|
||
```html | ||
{% render "Core:Index:index" %} | ||
``` | ||
|
||
The twig tag will call the action "index" from the "IndexController" located within the "Core" | ||
module and based on the returned value it will either render a specific template or output the | ||
returned value, following the same principles as with any other zf2 action. | ||
|
||
Optionally you can also specify different parameters to send to the processed action which can | ||
later be retrieved from the matched route: | ||
|
||
```html | ||
{% render "Core:Index:index" with {'param1':1} %} | ||
``` | ||
|
||
1. A tag for triggering an event on the renderer that is similar to the above syntax: | ||
|
||
|
||
```html | ||
{% trigger "myRendererEvent" on myObject with {'param1':1} %} | ||
``` | ||
|
||
Both the target object and parameters are optional. The result of each listener is | ||
converted to string and rendered intead of the definition. | ||
|
||
Also a new functionality allows the use of aliases within your template code or when | ||
rendering a template. | ||
converted to string and rendered intead of the definition. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,27 @@ | ||
<?php | ||
return array( | ||
'di' => array( | ||
'instance' => array( | ||
'alias'=>array( | ||
'view'=>'ZeTwig\View\Renderer' | ||
), | ||
// Inject the plugin broker for controller plugins into | ||
// the action controller for use by all controllers that | ||
// extend it. | ||
// 'Zend\Mvc\Controller\ActionController' => array( | ||
// 'parameters' => array( | ||
// 'broker' => 'Zend\Mvc\Controller\PluginBroker', | ||
// ), | ||
// ), | ||
// 'Zend\Mvc\Controller\PluginBroker' => array( | ||
// 'parameters' => array( | ||
// 'loader' => 'Zend\Mvc\Controller\PluginLoader', | ||
// ), | ||
// ), | ||
// 'Zend\View\Resolver\TemplateMapResolver' => array( | ||
// 'parameters' => array( | ||
// 'map' => array( | ||
// ), | ||
// ), | ||
// ), | ||
'Zend\View\Resolver\TemplatePathStack' => array( | ||
'parameters' => array( | ||
'defaultSuffix'=>'twig', | ||
), | ||
), | ||
'ZeTwig\View\Resolver'=>array( | ||
'injections' => array( | ||
'Zend\View\Resolver\TemplateMapResolver', | ||
'Zend\View\Resolver\TemplatePathStack', | ||
), | ||
), | ||
'ZeTwig\View\Renderer' => array( | ||
'parameters' => array( | ||
'broker' => 'Zend\View\HelperBroker', | ||
'environment'=>'ZeTwig\View\Environment', | ||
), | ||
), | ||
'Zend\Mvc\View\DefaultRenderingStrategy' => array( | ||
'parameters' => array( | ||
'layoutTemplate' => 'layouts/layout', | ||
), | ||
), | ||
'Zend\Mvc\View\ExceptionStrategy' => array( | ||
'parameters' => array( | ||
'displayExceptions' => true, | ||
'exceptionTemplate' => 'error/index', | ||
), | ||
), | ||
'Zend\Mvc\View\RouteNotFoundStrategy' => array( | ||
'parameters' => array( | ||
'displayNotFoundReason' => true, | ||
'displayExceptions' => true, | ||
'notFoundTemplate' => 'error/404', | ||
), | ||
'view_manager' => array( | ||
'display_not_found_reason' => true, | ||
'display_exceptions' => true, | ||
'layout' => 'layout/layout', | ||
'doctype' => 'HTML5', | ||
'not_found_template' => 'error/404', | ||
'exception_template' => 'error/index', | ||
'strategies' => array( | ||
'ze-twig' => 'ViewTwigRendererStrategy', | ||
) | ||
), | ||
|
||
'zendexperts_zetwig' => array( | ||
'template_suffix' => 'twig', | ||
'extensions' => array( | ||
'ZeTwig' => 'ZeTwig\View\Extension' | ||
), | ||
'ZeTwig\View\Environment'=>array( | ||
'injections' => array( | ||
'ZeTwig'=>'ZeTwig\View\Extension' | ||
), | ||
'parameters' => array( | ||
'loader' => 'ZeTwig\View\Resolver', | ||
'options' => array( | ||
'cache' => BASE_PATH . '/data/cache/twig', | ||
'auto_reload' => true, | ||
'debug' => true | ||
), | ||
), | ||
'environment_options' => array( | ||
'cache' => BASE_PATH . '/data/cache/twig', | ||
'auto_reload' => true, | ||
'debug' => true | ||
), | ||
), | ||
), | ||
|
||
); |
Oops, something went wrong.