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?
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.
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”.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With