Magento: How do I put widgets into a layout xml?

13,576

Solution 1

Turns out, it wasn't inserting any meaningful data because it wasn't receiving its parameters. It needs non-standard parameters to be set through action tags:

<block type="enterprise_banner/widget_banner" name="hero_banners" as="hero_banners" template="banner/widget/hero.phtml">
    <action method="setDisplayMode"><value>fixed</value></action>
    <action method="setBannerIds"><value>4</value></action>
</block>

Solution 2

Since the topic has already been solved, I have an off topic solution

This could be set as a block within a .phtml file if required.

<?php echo $this->getLayout()->createBlock('enterprise_banner/widget_banner')->setBannerIds('4')->setDisplayMode('fixed')->setTemplate('banner/widget/block.phtml')->toHtml(); ?>
Share:
13,576
Paul Frazee
Author by

Paul Frazee

Updated on June 14, 2022

Comments

  • Paul Frazee
    Paul Frazee almost 2 years

    I am using Magento Enterprise Edition. It includes a widget for banners, which I want to use inside of my template, rather than from inside of a CMS-run content block. I succeeded in generating the output from inside of a content block:

    {{widget type="enterprise_banner/widget_banner" display_mode="fixed" rotate="series" banner_ids="4" template="banner/widget/block.phtml" unique_id="744a56c9a042cc9fa166163c12d869d9"}}
    

    Simple enough. So inside of my layout xml, I tried this:

    <block type="enterprise_banner/widget_banner" name="hero_banners" as="hero_banners" display_mode="fixed" rotate="series" banner_ids="4" template="banner/widget/block.phtml" unique_id="744a56c9a042cc9fa166163c12d869d9" />
    

    Same parameters; I just added name and as. And then, inside of my template...

    <?php echo $this->getChildHtml('hero_banners'); ?>
    

    But I get no output. The profiler notes that the hero_banners block is loaded, but its template file (banner/widget/block.phtml) is never run.

    Does anybody know what I'm doing wrong?

    -P

  • benz001
    benz001 over 11 years
    This only seems works (at least in 1.6.2) if the widget block is a child of a core/text_list block, putting a widget like this straight into the root block doesn't appear to render.