定制 shapecode/twig-template-event-bundle 二次开发

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

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

shapecode/twig-template-event-bundle

最新稳定版本:6.0.0

Composer 安装命令:

composer require shapecode/twig-template-event-bundle

包简介

Possibility to add code in a twig template dynamically

README 文档

README

paypal

PHP Version Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads License

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:

composer require shapecode/twig-template-event-bundle

... or ...

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

If you dont use Symfony Flex you have to add ShapecodeTwigTemplateEventBundle to your bundles.php:

<?php
// config/bundles.php

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

Now you can set events in twig templates:

{{ event('test') }}

And listen to them with an event listener:

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'
                    ],
                )
            );
        }
    }
}

统计信息

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

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-10