定制 intaro/twig-injection-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

intaro/twig-injection-bundle

最新稳定版本:v3.0.0

Composer 安装命令:

composer require intaro/twig-injection-bundle

包简介

The TwigInjectionBundle allows to inject twig templates through the event behavior

README 文档

README

The TwigInjectionBundle allows to inject twig templates through the event behavior.

Installation

TwigInjectionBundle requires Symfony 3.4 or higher.

Require the bundle in your composer.json file:

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

Register the bundle in AppKernel:

// app/AppKernel.php

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

        new Intaro\TwigInjectionBundle\IntaroTwigInjectionBundle(),
    ];

    //...
}

Install the bundle:

$ composer update intaro/twig-injection-bundle

Usage

  1. Add {{ inject() }} calling in template:
{{ inject('twig.injection.event.name', { parameter1: 'some-value', parameter2: some_object }) }}
  1. Prepare controller action which you want to render or template which you want to include.

  2. Define Listener which will inject include or render calling:

<?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);
    }
}
  1. Register the listener:
services:
    acme_demo.twig_injection.listener:
        class: Acme\DemoBundle\EventListener\TwigInjectionListener
        tags:
            - { name: kernel.event_listener, event: twig.injection.event.name, method: onSomeEvent }

统计信息

  • 总下载量: 674.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 5
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-04