Please help solve this puzzle.
I'm created after plugin, after load category widget. The collection of items must be used in the js. The idea is to simply intercept the collection in the plugin, load it to the front in the .phtml template and process it in it. My plugin code

namespace Vendor\Module\Plugin;

use Magento\Framework\View\Element\Template;

class ParceWidget
    protected $blockFactory;

    public function __construct(
        \Magento\Framework\View\Element\BlockFactory $blockFactory
    ) {
        $this->blockFactory = $blockFactory;

    public function afterCreateCollection(
        \Magento\CatalogWidget\Block\Product\ProductsList $subject,
    ) {

        return $itemsCollection;
    protected function parceWidgetInformation($itemsCollection)
        $block = $this->blockFactory->createBlock(
                'data' => [
                    'widget_items' => $itemsCollection



    <?php if ($items = $this->getData('widget_items')):?>
        <?php //var_dump($items); die();?>
        <?php foreach ($items as $item): ?>
                <li><?= $item->getData()?></li>
        <?php endforeach;?>
    <?php endif;?>

I have omitted some of the standard points, leaving the gist.
So, if you write any content in widget.phtml, then at the end of loading the page on the front will not be displayed. But if you stop the download page process by doing for example:
<?php var_dump($items')); die();?>
In this case, everything will be in place. Here I have a question, where does the data disappear in the process of loading the page, because you can see that the template is loaded and the data can be obtained in it?

  • please paste widget.phtml Nov 23, 2020 at 20:44
  • @BilalUsean - thanks for viewed, updated post
    – Dmitry Zar
    Nov 23, 2020 at 21:07


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.