2017 © Pedro Peláez
 

symfony-bundle twig-template-event-bundle

Possibility to add code in a twig template dynamically

image

shapecode/twig-template-event-bundle

Possibility to add code in a twig template dynamically

  • Wednesday, August 1, 2018
  • by Nicklog
  • Repository
  • 1 Watchers
  • 4 Stars
  • 1,079 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 21 Versions
  • 3 % Grown

The README.md

Shapecode - Twig Template Event Bundle

paypal, (*1)

PHP Version Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads License, (*2)

Give you the possibility to add code in a twig template dynamically., (*3)

Install instructions

First you need to add shapecode/twig-template-event-bundle to composer.json:, (*4)

composer require shapecode/twig-template-event-bundle

... or ..., (*5)

{
   "require": {
        "shapecode/twig-template-event-bundle": "~5.0"
    }
}

If you dont use Symfony Flex you have to add ShapecodeTwigTemplateEventBundle to your bundles.php:, (*6)

<?php
// config/bundles.php

return [
    // ...
    Shapecode\Bundle\TwigTemplateEventBundle\ShapecodeTwigTemplateEventBundle::class => ['all' => true],
];

Now you can set events in twig templates:, (*7)

{{ event('test') }}

And listen to them with an event listener:, (*8)

services:
    # twig events
    Shapecode\Bundle\TwigTemplateEventBundle\EventListener\TestTwigEventListener: ~
<?php

namespace Shapecode\Bundle\TwigTemplateEventBundle\EventListener;

use Shapecode\Bundle\TwigTemplateEventBundle\Event\Code\TwigEventString;
use Shapecode\Bundle\TwigTemplateEventBundle\Event\Code\TwigEventInclude;
use Shapecode\Bundle\TwigTemplateEventBundle\Event\TwigTemplateEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener]
class TestTwigEventListener
{
    public function __invoke(TwigTemplateEvent $event): void
    {
        if ($event->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'
                    ],
                )
            );
        }
    }
}

The Versions

23/06 2015
04/04 2015
06/02 2015

1.1.2

1.1.2.0 http://shapecode.de

Possibility to add code in a twig template dynamically

  Sources   Download

MIT

The Requires

 

twig template bundle dispatcher event event listener injection shapecode

04/02 2015

1.1.1

1.1.1.0 http://shapecode.de

Possibility to add code in a twig template dynamically

  Sources   Download

MIT

The Requires

 

twig template bundle dispatcher event event listener injection shapecode

19/01 2015

1.1.0

1.1.0.0 http://shapecode.de

Possibility to add code in a twig template dynamically

  Sources   Download

MIT

The Requires

 

twig template bundle dispatcher event event listener injection shapecode

17/01 2015

1.0.0

1.0.0.0 http://shapecode.de

Possibility to add code in a twig template dynamically

  Sources   Download

MIT

The Requires

 

twig template bundle dispatcher event event listener shapecode

11/01 2015

1.0.0-alpha2

1.0.0.0-alpha2 http://shapecode.de

Possibility to add code in a twig template dynamically

  Sources   Download

MIT

The Requires

 

twig template bundle dispatcher event event listener shapecode

10/01 2015

1.0.0-alpha1

1.0.0.0-alpha1 http://shapecode.de

Possibility to add code in a twig template dynamically

  Sources   Download

MIT

The Requires

 

twig template bundle dispatcher event shapecode