Hello Magento Friends,

In today’s blog, we will learn about how to add an image chooser in the Magento 2 widget.

Magento 2 offers a robust platform for creating custom widgets. Enhancing these widgets with image chooser functionality empowers store owners to visually enrich their content. This guide will walk you through the steps to integrate an image chooser into your Magento 2 widget.

Steps to Add Image Chooser in Magento 2 Widget:

Step 1: Create a widget.xml file in the path given below.

{{magento_root}}\app\code\Vendor\Extension\etc\widget.xml

Now include the below-mentioned code

Step 2: Create PageWidget.php file in path given below.

{{magento_root}}\app\code\Vendor\Extension\Block\Widget\PageWidget.php

Then add the code as follows

Step 3: Create page_widget.phtml file in path given below.

{{magento_root}}\app\code\Vendor\Extension\view\frontend\templates\widget\page_widget.phtml

Now add the code given below

Step 4: Create ImageChooser.php file in path given below.

{{magento_root}}\app\code\Vendor\Extension\Block\Adminhtml\Widget\ImageChooser.php

Then add the following code

Step 5: Create a di.xml in path given below.

{{magento_root}}\app\code\Vendor\Extension\etc\di.xml

Then include the following code

Step 6: Create a Widget.php in path given below.

{{magento_root}}\app\code\Vendor\Extension\Plugin\Widget.php

Then after, add the below piece of code

Output:

widget

Conclusion:

Adding an image chooser to a custom Magento 2 widget is a straightforward process that enhances the flexibility and functionality of your widgets. By following the steps outlined in this guide, you can create a more dynamic and user-friendly interface for your Magento 2 store.

Feel free to customize the widget further to meet your specific needs!

Happy Coding!

Click to rate this post!
[Total: 1 Average: 5]