Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add widget to layout in Magento 2?

Tags:

magento2

Is there a way to add widget to the layout xml? I know about the layout updates from the backend, but I wanted to know if there is a way to add widgets the same way as static blocks?

like image 626
V.S Avatar asked Jul 22 '16 08:07

V.S


People also ask

How do I create a custom sidebar in Magento 2?

On the Admin Panel, Content > Elements > Pages . Choose the page where you want to place the block, then open the edit mode. On the left panel, select the Design tab, in the Layout Update XML box, insert the code for the right or left sidebar.

What is block and widget in Magento 2?

In Magento, a Block is just a piece of content. It's the Widget that controls the placement of the Block. However, that's not all a Widget can do. A Widget can place our simple, new Blocks, but it can also place many other features. Go to “Content”, and then “Widgets”.


1 Answers

you can add widget via followings xml ,

<referenceContainer name="content.top">
    <block class="Magento\Catalog\Block\Category\Widget\Link" name="demoBlock" template="widget/static_block/default.phtml">
        <action method="setData">
            <argument name="id_path" xsi:type="string">category/20</argument>
            <argument name="title" xsi:type="string">Demo Category Title</argument>
            <argument name="template" xsi:type="string">category/widget/link/link_inline.phtml</argument>
        </action>
    </block>
</referenceContainer>

you need to update followings

  • referenceContainer as per you needs
  • Block Class & Template (if you require to update the template for block)
  • arguments in setData
like image 181
Emizen Tech Avatar answered Oct 17 '22 15:10

Emizen Tech