{"id":18496919,"url":"https://github.com/shapecode/twig-template-event-bundle","last_synced_at":"2025-04-09T00:30:29.107Z","repository":{"id":57048932,"uuid":"60514055","full_name":"shapecode/twig-template-event-bundle","owner":"shapecode","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-07T10:51:04.000Z","size":222,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T19:39:08.107Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shapecode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"nicklog","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"nicklog","issuehunt":null,"otechie":null,"custom":["http://paypal.me/nloges"]}},"created_at":"2016-06-06T09:03:02.000Z","updated_at":"2024-06-15T22:21:46.000Z","dependencies_parsed_at":"2024-01-07T12:01:58.470Z","dependency_job_id":null,"html_url":"https://github.com/shapecode/twig-template-event-bundle","commit_stats":{"total_commits":61,"total_committers":8,"mean_commits":7.625,"dds":0.7540983606557377,"last_synced_commit":"599c3796e74c6b13c82c2748657859609e5696e5"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shapecode%2Ftwig-template-event-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shapecode%2Ftwig-template-event-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shapecode%2Ftwig-template-event-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shapecode%2Ftwig-template-event-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shapecode","download_url":"https://codeload.github.com/shapecode/twig-template-event-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608156,"owners_count":20965950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T13:32:33.625Z","updated_at":"2025-04-09T00:30:28.621Z","avatar_url":"https://github.com/shapecode.png","language":"PHP","funding_links":["https://github.com/sponsors/nicklog","https://liberapay.com/nicklog","http://paypal.me/nloges"],"categories":[],"sub_categories":[],"readme":"Shapecode - Twig Template Event Bundle\n=======================\n\n[![paypal](https://img.shields.io/badge/Donate-Paypal-blue.svg)](http://paypal.me/nloges)\n\n[![PHP Version](https://img.shields.io/packagist/php-v/shapecode/twig-template-event-bundle.svg)](https://packagist.org/packages/shapecode/twig-template-event-bundle)\n[![Latest Stable Version](https://img.shields.io/packagist/v/shapecode/twig-template-event-bundle.svg?label=stable)](https://packagist.org/packages/shapecode/twig-template-event-bundle)\n[![Latest Unstable Version](https://img.shields.io/packagist/vpre/shapecode/twig-template-event-bundle.svg?label=unstable)](https://packagist.org/packages/shapecode/twig-template-event-bundle)\n[![Total Downloads](https://img.shields.io/packagist/dt/shapecode/twig-template-event-bundle.svg)](https://packagist.org/packages/shapecode/twig-template-event-bundle)\n[![Monthly Downloads](https://img.shields.io/packagist/dm/shapecode/twig-template-event-bundle.svg)](https://packagist.org/packages/shapecode/twig-template-event-bundle)\n[![Daily Downloads](https://img.shields.io/packagist/dd/shapecode/twig-template-event-bundle.svg)](https://packagist.org/packages/shapecode/twig-template-event-bundle)\n[![License](https://img.shields.io/packagist/l/shapecode/twig-template-event-bundle.svg)](https://packagist.org/packages/shapecode/twig-template-event-bundle)\n\n\nGive you the possibility to add code in a twig template dynamically.\n\nInstall instructions\n--------------------------------\n\nFirst you need to add `shapecode/twig-template-event-bundle` to `composer.json`:\n```bash\ncomposer require shapecode/twig-template-event-bundle\n```\n... or ...\n```json\n{\n   \"require\": {\n        \"shapecode/twig-template-event-bundle\": \"~5.0\"\n    }\n}\n```\n\nIf you dont use Symfony Flex you have to add `ShapecodeTwigTemplateEventBundle` to your `bundles.php`:\n\n```php\n\u003c?php\n// config/bundles.php\n\nreturn [\n    // ...\n    Shapecode\\Bundle\\TwigTemplateEventBundle\\ShapecodeTwigTemplateEventBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\nNow you can set events in twig templates:\n\n```twig\n{{ event('test') }}\n```\n\nAnd listen to them with an event listener:\n\n```yaml\nservices:\n    # twig events\n    Shapecode\\Bundle\\TwigTemplateEventBundle\\EventListener\\TestTwigEventListener: ~\n```\n\n```php\n\u003c?php\n\nnamespace Shapecode\\Bundle\\TwigTemplateEventBundle\\EventListener;\n\nuse Shapecode\\Bundle\\TwigTemplateEventBundle\\Event\\Code\\TwigEventString;\nuse Shapecode\\Bundle\\TwigTemplateEventBundle\\Event\\Code\\TwigEventInclude;\nuse Shapecode\\Bundle\\TwigTemplateEventBundle\\Event\\TwigTemplateEvent;\nuse Symfony\\Component\\EventDispatcher\\Attribute\\AsEventListener;\n\n#[AsEventListener]\nclass TestTwigEventListener\n{\n    public function __invoke(TwigTemplateEvent $event): void\n    {\n        if ($event-\u003egetEventName() == 'foo') {\n        \n            // to add a string\n            $event-\u003eaddCode(\n                new TwigEventString(\n                    'hello {{ world }}', \n                    [\n                        'world' =\u003e 'World'\n                    ],\n                    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.\n                )\n            );\n        }\n        \n        if ($event-\u003egetEventName() == 'bar') {\n        \n            // to include a twig template\n            $event-\u003eaddCode(\n                new TwigEventInclude(\n                    '@App/Layout/Header/_search.html.twig', \n                    [\n                        'world' =\u003e 'World'\n                    ],\n                )\n            );\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshapecode%2Ftwig-template-event-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshapecode%2Ftwig-template-event-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshapecode%2Ftwig-template-event-bundle/lists"}