Magento – Widget Frontend Display

magento-1.9PHPwidgetwidgets

I managed to develop a custom widget, the problem is that its not displaying in the frontend.

The goal is to add the widget to a static block and then display the block in frontend.

I created the static block and added the widget, for test purposes was added some static text after the widget so to make sure the block is displaying and it does (the static text displays, but the widget content doesn't);

In the Block class in my widget i have the following code.

    class MP_Novidades_Block_Produtos
    extends Mage_Core_Block_Template
    implements Mage_Widget_Block_Interface
{

    public function _toHtml () {
        $_data = $this->getData();
        return "<a href='#'>Test</a>";
    }

}

In the layout file – page.xml i added this block.

 <block type="cms/block" name="banners_block" before="-">
            <action method="setBlockId">
                <block_id>banners_block</block_id>
            </action>
        </block>

widget.xml

 <?xml version="1.0"?>
 <widgets>
<novidades_nov type="novidades/produtos">
    <name>Produtos Novidade</name>
    <description type="desc">Cria lista de produtos novidade</description>
    <parameters>
        <hyperlink>
            <required>1</required>
            <visible>1</visible>
            <value>http://www.maispormenos.eu</value>
            <label>URL de ligação</label>
            <type>text</type>
        </hyperlink>
        <button_text>
            <required>1</required>
            <visible>1</visible>
            <value>Ir</value>
            <label>Texto do botão</label>
            <type>text</type>
        </button_text>
        <image>
            <required>1</required>
            <visible>1</visible>
            <value>-</value>
            <label>Imagem</label>
            <type>text</type>
        </image>
    </parameters>
  </novidades_nov>
</widgets>

it's supposed to show that tag, but it doesnt. What can be the causes for this to happen?

Thanks in advance and happy Magento programming!

Best Answer

Best tutorial I have ever found to create custom widgets is http://code.tutsplus.com/tutorials/custom-widget-development-in-magento--cms-23015

Please match your process with this tutorial. I hope it will surely help you.

Related Topic