I need to insert a javascript object into the head of my listing pages containing a json representation of the products listed on that page, ie not all products in the category but only those that have been paged by the toolbar.
I've found that I can get that data by putting an observer on catalog_block_product_list_collection but this is after the Head Block has been rendered, so therefore prevents me using that data in a child block of the Head.
As far as I can see I've got two options.
I wondered which way experienced Magento developers would jump and the pitfalls of both techniques, Thanks in advance.
So you already have added a custom block to the header, if I got you right, if so, you should be able to just retrieve the product collection from the list block.
$this->getLayout()->getBlock('product_list')->getLoadedProductCollection();
I might have misunderstood your question, but maybe it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.