2017 © Pedro Peláez
 

symfony-bundle twig-injection-bundle

The TwigInjectionBundle allows to inject twig templates through the event behavior

image

intaro/twig-injection-bundle

The TwigInjectionBundle allows to inject twig templates through the event behavior

  • Tuesday, February 27, 2018
  • by muxx
  • Repository
  • 3 Watchers
  • 3 Stars
  • 16,972 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 6 Versions
  • 10 % Grown

The README.md

TwigInjectionBundle

The TwigInjectionBundle allows to inject twig templates through the event behavior., (*1)

Installation

TwigInjectionBundle requires Symfony 3.4 or higher., (*2)

Require the bundle in your composer.json file:, (*3)

{
    "require": {
        "intaro/twig-injection-bundle": "^2.0"
    }
}

Register the bundle in AppKernel:, (*4)

// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        //...

        new Intaro\TwigInjectionBundle\IntaroTwigInjectionBundle(),
    ];

    //...
}

Install the bundle:, (*5)

$ composer update intaro/twig-injection-bundle

Usage

1) Add {{ inject() }} calling in template:, (*6)

{{ inject('twig.injection.event.name', { parameter1: 'some-value', parameter2: some_object }) }}

2) Prepare controller action which you want to render or template which you want to include., (*7)

3) Define Listener which will inject include or render calling:, (*8)

<?php

namespace Acme\DemoBundle\EventListener;

use Intaro\TwigInjectionBundle\Event\TwigInjectEvent;
use Intaro\TwigInjectionBundle\Event\TwigInjectRender;

class TwigInjectionListener
{
    public function onSomeEvent(TwigInjectEvent $event)
    {
        $parameters = $event->getParameters();

        if (!isset($parameters['parameter1']) || 'some-value' !== $parameters['parameters1']) {
            return;
        }

        $render = new TwigInjectRender(
            'AcmeDemoBundle:DefaultController:index',
            [ 'object' => $parameters['parameters2'] ]
        );
        $event->addInjection($render);

        $include = new TwigInjectInclude('AcmeDemoBundle:Default:someTemplate.html.twig');
        $event->addInjection($include);
    }
}

4) Register the listener:, (*9)

services:
    acme_demo.twig_injection.listener:
        class: Acme\DemoBundle\EventListener\TwigInjectionListener
        tags:
            - { name: kernel.event_listener, event: twig.injection.event.name, method: onSomeEvent }

The Versions

27/02 2018

dev-master

9999999-dev

The TwigInjectionBundle allows to inject twig templates through the event behavior

  Sources   Download

MIT

The Requires

 

by Intaro Soft

twig symfony2 event

27/02 2018

v1.1.0

1.1.0.0

The TwigInjectionBundle allows to inject twig templates through the event behavior

  Sources   Download

MIT

The Requires

 

by Intaro Soft

twig symfony2 event

10/02 2017

v1.0.1

1.0.1.0

The TwigInjectionBundle allows to inject twig templates through the event behavior

  Sources   Download

MIT

The Requires

 

by Intaro Soft

twig symfony2 event

10/02 2017

v1.0.0

1.0.0.0

The TwigInjectionBundle allows to inject twig templates through the event behavior

  Sources   Download

MIT

The Requires

 

by Intaro Soft

twig symfony2 event

05/08 2014

v0.1.0

0.1.0.0

The TwigInjectionBundle allows to inject twig templates through the event behavior

  Sources   Download

MIT

The Requires

 

by Intaro Soft

twig symfony2 event

04/08 2014

v0.0.1

0.0.1.0

The TwigInjectionBundle allows to inject twig templates through the event behavior

  Sources   Download

MIT

The Requires

 

by Intaro Soft

twig symfony2 event