So I have a really interesting question.

I have a block that depends on Magento\Catalog\Block\Product\ListProduct.

Basically I need to load this block after the collection is generated.

I'm using getLoadedProductCollection method to load the collection.

In my layout this block is in the header, so when I call this method in header, I expect the collection to load, but instead it returns an empty collection.

When I call it after the \Magento\Catalog\Block\Product\ListProduct is loaded, then I get the expected collection.

But then this block is at the end of the page.

I could move this block by using jQuery, but I'm trying to avoid such a workaround.

What's is the best way to generate this block in header and have the collection loaded in Magento\Catalog\Block\Product\ListProduct.


  • don't be complicated, I think you are not placed your block inside the correct reference block /container, could you show your layout file? Aug 14 '17 at 21:40
  • @BilalUsean That's the thing. If I place my block after <block class="Magento\Catalog\Block\Product\ListProduct"> it works fine, but I need to load it in header.
    – brusko
    Aug 14 '17 at 22:40
  • after load, you can use <move ../> to move your block inside whatever container/block, easy for your reference magento.stackexchange.com/a/117989/36463 Aug 14 '17 at 22:57
  • @BilalUsean it doesn't work like that. I wish I could load the element first and than move it. The issue is that when you move element, magento loads blocks in final order of xml files, which includes if there were any changes to layout with move element.
    – brusko
    Aug 15 '17 at 15:00

The first thing that comes to my mind right now is, have you tried setting your module to load after Magento_Catalog?


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_ModuleName" setup_version="1.0.0">
            <module name="Magento_Catalog" />
  • Yeah, I tried it too. Seems like it doesn't work in terms of blocks, because even if I have sequence in place, it still doesn't load the collection
    – brusko
    Aug 14 '17 at 21:19

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.