How to Create Custom Widget in Magento 2

Blog
Spread the love

Widgets provides powerful feature that are used to adding static or dynamic content in any
store’s pages and blocks.

Widgets are reusable component and with configurable parameter you can use the same widget in different number of pages with different parameter value.

There are some by defaults widget magento provided.

CMS Page Link

CMS Static Block

Catalog Category Link

Catalog New Products List

Catalog Product Link

Catalog Products List

Orders and Returns

Recently Compared Products

Recently Viewed Products

First of all, creating for custom widget we need to create simple module
Here I will be using the Bluethinkinc_CustomWidget as my module.

Create theregistration.php file in the app/code/Bluethinkinc/CustomWidget folder.

Now, for declaring a widget we need to create widget.xml file in the app/code/Bluethinkinc/ CustomWidget/etc folder.

Here in the widget,

class – name of the widget class

description- contains a concise explanation of the widget’s purpose

label – name of the widget which will be display in the widget list.

parameter – The parameter node allows you to add different parameters like text,select,multiselect,block.

id- custom Id of widget It should be unique.

Now we need to create a block file for the widget as defined in widget.xml. So create the CustomWidget.php file in the app/code/Bluethinkinc/ CustomWidget/Block/Widget folder.

In the above file, $_template is used to set the template for the widget.

We have set the $_template value to “widget/customwidget.phtml”. So it will search for the customwidget.phtml file in the app/code/Bluethinkinc/ CustomWidget/view/frontend/templates/widget folder.

Now, we have to create customWidget.phtml file in the

app/code/Bluethinkinc/ CustomWidget/view/frontend/templates/widget folder.

That’s it !!!

Now,After clearing the cache, the new widget My New Custom Widget
should be available.

widget_In_magento

widget_In_magento
widget_In_magento

I hope this blog is easy to understand about how to create custom widget in Magento 2.

bluethinkinc_blog

bluethinkinc_blog

2023-02-16

0

Leave a Reply

Your email address will not be published. Required fields are marked *

Find More Blogs

How to Add a Custom Tab to the Customer Order Detail Page in Magento 2

Spread the love Adding a custom tab to the Order Detail

Exception Handling in Java

Spread the love Introduction – Exception:An unwanted

How to add custom less file in Magento2

Spread the love Source files *.css included into layout

Spring Boot Microservices

Spread the love Microservices architecture has become

Implementation of WireMock for better testing

Spread the love WireMock is a flexible and powerful tool

Magento 2: How to selected default option in configurable options?

Spread the love Configurable products in Magento 2 allow

How To Implement Simple JWT Authentication in Django Rest Framework

Spread the love We’ll learn how to use simple JWT

Optimizing Search: Integrating Elasticsearch in Django Applications

Spread the love What is Elasticsearch? Elasticsearch is a

How to create Customer Segments

Spread the love In Magento 2, “customer

Proxy Design Pattern and Requisition List in Magento 2

Spread the love Requisition List in Magento 2 Requisition

bluethinkinc Blogs