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

Customize lead qualification for a seamless experience

Spread the love When the 2024 Release Wave 2 was launched,

Create a Custom Console Command in Spryker

Spread the love In Spryker, developers can create custom

SALESFORCE

Spread the love Salesforce is a cloud-based software

CRUD Operation in Spryker Backoffice with a Custom Module

Spread the love Spryker is a highly flexible and modular

How to create custom module on Spryker for Backoffice?

Spread the love Creating a custom module in Spryker

How to Install Spryker Project with Docker on Local Machine

Spread the love Spryker is a flexible and scalable commerce

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

bluethinkinc Blogs