我希望使用自定义模块自定义Magento\Theme\Block\Html\Footer class。
输出:Hello!
di.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Theme\Block\Html\Footer">
<plugin name="footer-text-override" type="Hello\Test\Plugin\Footer" sortOrder="15" />
</type>
</config>Footer.php
<?php
namespace Hello\Test\Plugin;
use Magento\Framework\View\Element\Template;
class Footer extends \Magento\Theme\Block\Html\Footer
{
public function getCopyright()
{
echo "Hello World!";
}
}但这不管用。
发布于 2017-08-16 12:45:58
为什么要重写一个类来更改文本?Magento提供了一个功能来更改页脚的文本。
转到:管理>内容>设计>配置
单击“商店”视图的编辑操作。现在,向下滚动页面,有页脚部分,展开它,并在版权字段中输入您的文本。
保存它并刷新缓存.


发布于 2017-08-16 08:25:12
若要在magento2中重写页脚版权文本,可以使用首选项而不是插件。
因此,您的di.xml如下所示。
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Theme\Block\Html\Footer" type="Hello\Test\Plugin\Footer" />
</config>首选项用于重写类。它类似于magento1中的类重写。
插件允许我们在类的任何公共方法之前、之后和周围执行代码。(http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html)
https://stackoverflow.com/questions/45670212
复制相似问题