0

I want to override _getHtml() function from topmenu.php file using block. So Please help me

THANKS.

4
  • Can you please tell here what you want to perform? – Rohan Hapani Jul 19 at 12:26
  • i want to simply override topmenu.php file function using block. – Mohit Patel Jul 19 at 12:31
  • override file working for you? – Rohan Hapani Jul 20 at 12:32
  • 1
    i will try this thanks bro – Mohit Patel Jul 20 at 13:13
1

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
}

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.