开发者

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开发者_Python百科 template file (banner/widget/block.phtml) is never run.

Does anybody know what I'm doing wrong?

-P


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>


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(); ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜