Download the PHP package maceda/twig-composer without Composer
On this page you can find all versions of the php package maceda/twig-composer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maceda/twig-composer
More information about maceda/twig-composer
Files in maceda/twig-composer
Package twig-composer
Short Description Callback library for Twig
License Public Domain
Homepage https://github.com/AlvaroMaceda/twig-composer
Informations about the package twig-composer
Twig Composer
A callback function library for Twig: you will be able to execute code when templates are rendered.
Useful for calling code like controllers, etc. before the template is rendered. This can be done in some frameworks as Symfony or Laravel, but this library works directly with Twig.
For example, if you have a template which can be included in a layout, you can do:
And then use the menu generated in template. You won't need to include a call to the service in each controller which uses the layout.
Getting Started
If you are using composer tool, you can start using TwigComposer requiring the library:
If not, please follow installation instructions.
To be notified of template renders, you need to indicate TwigComposer as the base class for templates when creating Twig_Environment:
To receive callbacks you must register them for each template you want to be notified:
will be called each time is rendered.
You can also inherit your own base class from TwigComposer if you need to use your own base class for Twig (do not forget to call parent methods when corresponding)
Installation
If you do not use composer, you must install and require the following dependencies:
You must also include and in your project to use this library.
Running the tests
This library uses PHPUnit for test. To run the test, execute this command:
If you want to generate code coverage information, just add the option
Contributing
Feel free to contribute to this code. Please send an email to the authors and / or a pull request to the project's repository: https://github.com/AlvaroMaceda/twig-composer
Authors
- Alvaro Maceda - Initial work
License
This project is Public Domain.
Acknowledgments
- Thanks to Christophe Robin for his port of event emmiter to PHP
- Inspired by View::composer feature of Laravel