I want to extend the \Magento\Sales\Block\Order\Email\Items\DefaultItems.php class so I can add an extra function instead of putting in the core file. (which works btw)

I tried it with creating a preference in my di.xml in my custom module like this;

<preference for="\Magento\Sales\Block\Order\Email\Items\DefaultItems"
                type="MyModule\MyVendor\Rewrite\Magento\Sales\Order\Email\Items\DefaultItems" />

Then extend the class like the this:


namespace MyModule\MyVendor\Rewrite\Magento\Sales\Order\Email\Items;

class DefaultItems extends \Magento\Sales\Block\Order\Email\Items\DefaultItems

     * DefaultItems constructor.
    public function __construct()

        die('Class extended');


When I make a functiongetSku() my IDE (PHPstorm) shows that it will be overridden like it supposed to. When sending an invoice email through the backend it will show me the die in the constructor.

When deleting the constructor (or the die) I am getting the following error message:

Unknown template engine type ".

So what am i missing here, any ideas?

1 Answer 1


I don't know why, but you have to set a template for your custom Block.

See How to override blocks in v2.1

For your example add following method:

MyModule\MyVendor\Rewrite\Magento\Sales\Order\Email\Items\DefaultItems .php

public function setTemplate($template)
    return parent::setTemplate('Vendor_Module::custom-menu.phtml');

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.