Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 745
Paul Frazee Avatar asked Jun 22 '10 16:06

Paul Frazee


1 Answers

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>
like image 93
Paul Frazee Avatar answered Oct 14 '22 05:10

Paul Frazee