php - 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}
任何帮助将非常感激。
解决方案
我记得append
-Keyword 不应该再在 Shopware 中使用。改为使用{$smarty.block.parent}
。您还应该创建一个 EventSubscriber 解释here。
如果这仍然不起作用,请检查您的缓存并确保插件已激活
推荐阅读
- mysql - 在 Docker 容器上使用 mysql 数据库的 Spring Boot 应用程序的 Maven 安装构建失败
- networking - 消息广播(在本地网络中)是客户端/服务器还是对等系统?
- javascript - 在 React 中,如何将“this.state”作为参数传递给“socket.on”回调函数?
- google-docs - 在 Google 文档中将黑色设置为默认颜色
- r - ggplot - 出现在图例中的额外标签
- python - Flask GET 请求被发送到错误的路径,导致 404
- javascript - 为什么缺少的函数参数的值为“[object Object]”?
- javascript - 使用 Twilio 时 Firestore 功能部署错误
- assembly - 用于打印到标准输出的“mov edx,Len”是否将“Len”的值或地址存储到寄存器中?
- python-3.x - 在 Python OOP 中你能帮我理解为什么这段代码不起作用