I am using Magento 2.2.6. In my custom module I add catalog_category_view.xml
add a block
<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="sidebar.main">
<block class="Vendor\Module\Block\CategoryListing" name="sidebar.vendor.category" before="catalog.navigation.renderer" cacheable="false" template="Vendor_Module::category_list.phtml"/>
</referenceContainer>
</body>
</page>
and class is as
class CategoryListing extends \Magento\Framework\View\Element\Template
{
public function __construct(
\Magento\Framework\View\Element\Template\Context $context
)
{
parent::__construct($context);
}
public function welcome()
{
.....
}
}
but page through error.
Fatal error: Uncaught Error: Call to a member function get() on null in /home/user/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:144 Stack trace: #0
But without class in layout xml as
<block name="sidebar.vendor.category" before="catalog.navigation.renderer" cacheable="false" template="Vendor_Module::category_list.phtml"/>
Works fine i.e. load category_list.phtml
with its content. But my target is using the block with class.
Where is the problem? Thanks!