Menu Close
    Start a Project Request quote Reading list Switch to dark mode
    magento-hyperlocal-marketplace-guide

    Create custom widget type in magento2

     

    Today i am explaining how to create custom widget type in magento2.

    To create widget firstly need to create widget.xml in app/code/Namespace/Module/etc/ folder.


    Here, Widget id: wk_customwidget, you can defined as per your choice.

    Class attribute: in this you need to add a block class which is used in your widget.

    label and description tags for the widget explanation.

    In the parameter tag we added 2 type of fields:

    1: text type, you can add text values.

    2: select type: to select option values, for this you need to define values in model.

    Model file for the select options at path: Webkul\CustomWidget\Model\Config\Source\Select.php

    will have code like:


    By this code, there are two option will appear with Yes and No values.

    Now Create block which is defined in widget.xml

    Block file at path Webkul\CustomWidget\Block\CustomWidget.php


    Here, you can set your custom template in $this->setTemplate() function.

    In block i created two functions to get values which i added at time of adding widget.

    After these files, you will get a new widget type with custom fields.

    You can add this widget on any page, and use widget’s data through your block.

    I hope, this blog will help you to create/add a new functionality in magento2.

     

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close