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

Proxy Design Pattern and Requisition List in Magento 2

Spread the love Requisition List in Magento 2 Requisition

Google Ads Conversion Tracking Through Magento Platform:

Spread the love Google Ads Conversion Tracking Through

Object Pool Pattern in Magento2

Spread the love What is Object Pool Pattern in Magento 2 An

JENKINS

Spread the love JENKINS Introduction and Installation

Virtual Type and Type

Spread the love Virtual type is one of the most common

Customize the length of Input field

Spread the love Sometimes we need to change the limit the

How to Add Custom Tab on Admin Dashboard and Count Website Total Visitor in Magento 2?

Spread the love In this blog we’ll see How to Add Custom

How to Add Sign Out Tab in Customer Account in Magento 2?

Spread the love In this blog we’ll see How to Add

How to create custom tab in product detail page in magento 2?

Spread the love In this blog we’ll see how to add

Understanding and Implementing CORS & CSRF

Spread the love What is security? The world has become more

bluethinkinc Blogs