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?
Asked
Active
Viewed 1.3k times
1 Answers
12
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

Emizen Tech
- 3,529
- 1
- 17
- 33
-
1Is there a way to specify a widget that has already been created in the backend? Maybe by using the widget id? – V.S Jul 28 '16 at 15:15
-
there is no need to do that in layout files admin widgets directly loads to selected configuration , there is configuration on each widget where you want to display that. – Emizen Tech Jul 28 '16 at 16:14
-
It works and I can set custom template as well. Thanks! – V.S Aug 08 '16 at 05:41
-
5I tried this with a custom widget that needed some arguments. They weren’t send to the widget correctly. After changing
to – Dennis van Schaik Nov 18 '16 at 10:30It worked like a charm.