I want to get specific widget configuration in phtml or block.

In that phtml/block i want to load custom product collection with filter using that widget data.

I want to create a same page like product listing(category page) after getting that collection.

I also referred below solution.

Use product list template with my own product collection?


I used ObjectManager but using the below code you can convert.

use \Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap     = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$instance      = \Magento\Framework\App\ObjectManager::getInstance();
$state         = $objectManager->get('\Magento\Framework\App\State');

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$widgetCollection = $objectManager->create('Magento\Widget\Model\Widget\Instance');
//$data = $widgetCollection->load(instanceId);
$data = $widgetCollection->load('1');
echo "<pre/>";

Result enter image description here

  • let me try once – Biren Patel Jan 9 at 9:03
  • Yes its working for me – Biren Patel Jan 9 at 9:05
  • Array ( [instance_id] => 169 [instance_type] => Vendor\Customwidget\Block\Widget\CustomwidgetCollection [theme_id] => 5 [title] => Deal Of The Week [store_ids] => 2 [widget_parameters] => {"block_title":"\u0635\u0641\u0642\u0629 \u0627\u0644\u0623\u0633\u0628\u0648\u0639","block_type":"best_deal","past_days":"1000","limit":"20","all_category":"1"} [sort_order] => 0 ) – Biren Patel Jan 9 at 9:05

use parameters in widget.xml

        <parameter name="category_id" sort_order="10" visible="true" xsi:type="text">

you can get this value in .phtml like

<?php echo $block->getData('category_id'); ?>

hope this will work for you.

  • will you please explain bit more in this? – liyakat Jan 8 at 12:55

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.