2010-06-22 61 views
11

我正在使用Magento企業版。它包含一個用於橫幅的小部件,我想在我的模板中使用它,而不是從CMS運行的內容塊中使用。我成功地從內容塊內部生成輸出:Magento:如何將小部件放入佈局xml中?

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

夠簡單。所以在我的佈局xml裏面,我試過這個:

<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" /> 

相同的參數;我只是添加了名字和as。然後,在我的模板裏面...

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

但是我沒有輸出。分析器注意到hero_banners塊被加載,但其模板文件(banner/widget/block.phtml)從未運行。

有人知道我在做什麼錯嗎?

-P

回答

19

事實證明,它不插入任何有意義的數據,因爲它沒有接收到它的參數。它需要非標參數,通過動作標籤設置:

<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> 
+1

這似乎只工作(至少在1.6.2),如果該部件塊是核心/ text_list塊的孩子,把這樣的小部件直入根塊不會出現渲染。 – benz001 2012-09-26 10:55:26

2

既然話題已經解決了,我有一個題外話解決方案

這可以在一個.phtml文件中被設置爲一個塊如果需要。

<?php echo $this->getLayout()->createBlock('enterprise_banner/widget_banner')->setBannerIds('4')->setDisplayMode('fixed')->setTemplate('banner/widget/block.phtml')->toHtml(); ?>