I want to override _getHtml() function from topmenu.php file using block. So Please help me
THANKS.
I want to override _getHtml() function from topmenu.php file using block. So Please help me
THANKS.
You can override block by preference in di.xml file in your module :
<?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\Topmenu" type="Vendor\Module\Block\Html\Topmenu" />
</config>
Now, Create Topmenu.php file
app/code/Vendor/Module/Block/Html/Topmenu.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Vendor\Module\Block\Html;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\View\Element\Template;
class Topmenu extends Template implements IdentityInterface
{
//add override code here
}