0

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>
  • how you know it is not working? did you call HelloWorld method anywhere? – Agnes Aug 29 '17 at 10:34
  • Called $block->HelloWorldx(); in header.phtml file – Danial Butt Aug 29 '17 at 13:58
  • @Agnes But no output. – Danial Butt Aug 29 '17 at 13:59
  • is your module enabled? you can check the output of bin/magento module:status. Also if you add echo get_class($block) to your template file what do you get? – Kristof at Fooman Aug 29 '17 at 21:01
  • @ Kristof at Fooman yes my module is enabled and checked it twice. – Danial Butt Aug 30 '17 at 5:45
0

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.

| improve this answer | |
  • Hey @Evgeny Levinsky I already did that.But no luck yet. – Danial Butt Aug 30 '17 at 5:02
  • Send me all files in your module: etc/module.xml, registration.php and header.phtml, if it possible. I will check it in my environment – Evgeny Levinsky Aug 30 '17 at 8:24
  • all files ufile.io/a18ci – Danial Butt Aug 30 '17 at 8:26
  • Ok, thanks. Show me how the header block is called in your xml layout, I have any ideas. – Evgeny Levinsky Aug 30 '17 at 8:44
  • Called like echo $block->HelloWorldx(); – Danial Butt Aug 30 '17 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.