I'm playing overriding the blocks in magento 2, extended block constructor is calling but inside method is not working?

my code is


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Block\Account\Dashboard\Info" type="Learning\Customers\Block\Info" />



namespace Learning\Customers\Block;

use Magento\Framework\View\Element\Template;

class Info extends \Magento\Customer\Block\Account\Dashboard\Info

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
        \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
        \Magento\Customer\Helper\View $helperView,
        array $data = []
    ) {

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/Info.log');
        $logger = new \Zend\Log\Logger();

        parent::__construct($context,$currentCustomer,$subscriberFactory,$helperView, $data);

    public function getName()
        return 'Magento 2';


Any suggestions?


  • what do you mean by "not working"? what happens when you try it?
    – Marius
    Aug 4, 2015 at 14:22
  • @Marius, constructor() is calling, but getName() method is not overriding i.e., not displaying Magento 2 Aug 4, 2015 at 14:24
  • @Marius any help on this Aug 5, 2015 at 5:10

2 Answers 2


add below method to Info.php

protected function _toHtml()
        return parent::_toHtml();

see reference Link How to Overriding block in Magento 2


Overriding Block is done but issue is when i get current category id using registry in magento 2 showing error

There has been an error processing your request.
Object DOMDocument should be created

Any one know how can i get current category id in Toolbar block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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