首页 > 解决方案 > Enlight_Controller_Action_PreDispatch_Frontend 在 Plugin.php 类中不起作用

问题描述

我正在创建一个 shopware 5 插件。我想在每一页的类别之后显示一些东西。我正在使用此代码执行此视频中建议的任务,但该事件未得到识别。

这是我的代码

<?php
namespace MyPlugin;

use Shopware\Components\Plugin;

class MyPlugin extends Plugin{
    public static function getSubscribedEvents()
    {
        return [
            'Enlight_Controller_Action_PreDispatch_Frontend' => 'onPreDispatch'
        ];
    }

    public function onPreDispatch(\Enlight_Event_EventArgs $args)
    {
        $controller = $args->getSubject();
        $view = $controller->View();

        $view->addTemplateDir(__DIR__.'/Resources/views');
    }
}

前端/索引/index.tpl

{extends file="parent:frontend/index/index.tpl"}
{block name="frontend_index_navigation_categories_top" append}
    <div>my items here</div>
{/block}

任何帮助将非常感激。

标签: phpevent-handlingsymfony4shopware

解决方案


我记得append-Keyword 不应该再在 Shopware 中使用。改为使用{$smarty.block.parent}。您还应该创建一个 EventSubscriber 解释here

如果这仍然不起作用,请检查您的缓存并确保插件已激活


推荐阅读