https://github.com/shapecode/twig-template-event-bundle
https://github.com/shapecode/twig-template-event-bundle
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/shapecode/twig-template-event-bundle
- Owner: shapecode
- License: mit
- Created: 2016-06-06T09:03:02.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-01-07T10:51:04.000Z (about 2 years ago)
- Last Synced: 2025-03-23T19:39:08.107Z (12 months ago)
- Language: PHP
- Size: 217 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Shapecode - Twig Template Event Bundle
=======================
[](http://paypal.me/nloges)
[](https://packagist.org/packages/shapecode/twig-template-event-bundle)
[](https://packagist.org/packages/shapecode/twig-template-event-bundle)
[](https://packagist.org/packages/shapecode/twig-template-event-bundle)
[](https://packagist.org/packages/shapecode/twig-template-event-bundle)
[](https://packagist.org/packages/shapecode/twig-template-event-bundle)
[](https://packagist.org/packages/shapecode/twig-template-event-bundle)
[](https://packagist.org/packages/shapecode/twig-template-event-bundle)
Give you the possibility to add code in a twig template dynamically.
Install instructions
--------------------------------
First you need to add `shapecode/twig-template-event-bundle` to `composer.json`:
```bash
composer require shapecode/twig-template-event-bundle
```
... or ...
```json
{
"require": {
"shapecode/twig-template-event-bundle": "~5.0"
}
}
```
If you dont use Symfony Flex you have to add `ShapecodeTwigTemplateEventBundle` to your `bundles.php`:
```php
['all' => true],
];
```
Now you can set events in twig templates:
```twig
{{ event('test') }}
```
And listen to them with an event listener:
```yaml
services:
# twig events
Shapecode\Bundle\TwigTemplateEventBundle\EventListener\TestTwigEventListener: ~
```
```php
getEventName() == 'foo') {
// to add a string
$event->addCode(
new TwigEventString(
'hello {{ world }}',
[
'world' => 'World'
],
10 // default is 0. The higher the number the later the code will be executed. The lower the number the earlier the code will be executed.
)
);
}
if ($event->getEventName() == 'bar') {
// to include a twig template
$event->addCode(
new TwigEventInclude(
'@App/Layout/Header/_search.html.twig',
[
'world' => 'World'
],
)
);
}
}
}
```