In catalog_category_view.xml

    <referenceContainer name="content">
        <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="my-block-name" template="Vendor_Module::contents.phtml"/>

In content.phtml

 * Product list toolbar
 * @var $toolBarBlock \Magento\Catalog\Block\Product\ProductList\Toolbar

I get error:

"PHP message: PHP Fatal error:  Uncaught Error: Call to a member 
 function getSize() on null in 

Line 609:

     * @return int
    public function getTotalNum()
        return $this->getCollection()->getSize();

Not sure what I am missing anyone any idea?


Seems like your toolbar has no collection, but it is required. In the original magento layout the Toolbar block rendered inside the Magento\Catalog\Block\Product\ListProduct block, which access toolbar from the layout and set the product collection:


 * Need use as _prepareLayout - but problem in declaring collection from
 * another block (was problem with search result)
 * @return $this
protected function _beforeToHtml()
    $collection = $this->_getProductCollection();



    return parent::_beforeToHtml();

I think you should declare\create own toolbar block and rewrite the getCollection() method, or set it manually before layout render.

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.