I want to add custom block with custom logic to customer account. Is there any preferable inheritance in this case fro new block?

2 Answers 2


It depends on what you need.
For a simple text block \Magento\Framework\View\Element\Template should be enough.
If you add something in the dashboard you might want to use \Magento\Customer\Block\Account\Dashboard as a parent class. It already contains methods for retrieving the current customer, the account url, the address url.

  • I thought that there something maybe in sake of security and it is recommended to extend for. I have to prepare additional block with recently visited product for customer and it should be visible inside customer account. Jan 10, 2017 at 13:48
  • I think you can simply extend the template block and add a method in there that retrieves the current customer. The security part should be implemented in the controller. So if you use the block only in the customer account page you should be safe.
    – Marius
    Jan 10, 2017 at 13:50

Do not use inheritance, if it is not necessary.

Moreover, blocks are private classes of modules, this class may be modified in next versions of module.

Should not use extending \Magento\Customer\Block\Account\Dashboard for using only one method. This class have many dependencies, which not needed in your block. Inheritance will increase coupling between objects, arguments count, stability in your class and your module will become non-reliable.

Use inheritance from \Magento\Framework\View\Element\Template and implement only the necessary methods for you


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.