magento 2 override block \Magento\Theme\Block\Html\Header
-
11-12-2020 - |
سؤال
I am trying to override block \Magento\Theme\Block\Html\Header But it is not working at all no error. Any suggestion?
Created new module. Header.php code
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Webkul\MagentoTheme\Block\Html;
/**
* Html page header block
*/
class Header extends \Magento\Theme\Block\Html\Header
{
public function HelloWorld()
{
echo "Hello World Dear Hamza ......................................";
die();
}
}
etc/di.xml code
<?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\Header" type="Webkul\MagentoTheme\Block\Html\Header" />
</config>
المحلول
Did you upgrade and clean the cache?
php bin/magento setup:upgrade
php bin/magento cache:clean
If no - do it, please. I did not find mistakes in above code.
لا تنتمي إلى magento.stackexchange