I am new to this Magento platform.

I want to create a custom widget to retrieve the price so that I can use it just by calling the widget on the front page.

May anyone help me?

1 Answer 1


You can create one block file in your custom module like

path app/code/YourVendor/YourModule/Block/PriceWidget.php

namespace YourVendor\YourModule\Block;

use Magento\Framework\View\Element\Template;
use Magento\Widget\Block\BlockInterface;

class PriceWidget extends Template implements BlockInterface
    // Implement logic here to retrieve the product price.

create widget.xml in the following path


<?xml version="1.0"?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:widget:1.0">
    <widget id="yourmodule_price_widget" class="YourVendor\YourModule\Block\PriceWidget">
        <label translate="true">Price Widget</label>
        <description translate="true">Display product price.</description>
            <!-- Add widget parameters here if needed -->

In the Magento Admin Panel, you can now insert your custom widget into a CMS page or block. Go to the CMS page or block where you want to display the price and use the widget insertion tool to add your custom widget.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.