Magento set custom template to render widget instance

magentowidget

I'm trying to render a widget instance with a custom template. In the admin, in my CMS Homepage, in the Layout Updates XML section I've added the following code:

<reference name="right.hp_right_hot_items">
<block type="mih_banner/widget_banner" template="banner/widget/block-right.phtml"/>
</reference>

where 'hp_right_hot_items' is the Widget Instance Title, but for some reason the template is not set properly.

In the widget instance fronted properties I've set a layout update:

Display On: Specific Page

Page: CMS Home Page

Block Reference: Right Column

Template: Banner Block Template

Any ideas?

Best Answer

In order to render a widget with a custom template you have to do the following:

  1. Create a yourfile.phtml template on the desired location
  2. Create a widget.xml file in yourModule/etc/ and add another value to the template parameters. Ex:
<parameters>
    <template>
        <values>
            <block_right translate="label">
                <value>{path_to}/yourfile.phtml</value>
                <label>Banner Block Template {custom name}</label>
            </block_right>
        </values>
    </template>
</parameters>

Now, when you go to admin to add another widget instance, in the layout updates section you should be able to select the template just added.

Related Topic