Widget – Calling a Template from Within a Widget in Magento

layouttemplatewidgetxml

I'm designing a new products widgets that will be used in our CMS page. I'd like to call the toolbar.phtml file in order to display some information on the page, however, i'm unsure where to add this file within the .xml page and how to call this template. This widget is located at:

…/magento/app/design/frontend/enterprise/default/template/catalog/product/widget/new/content/new_grid.phtml

Any help or elucidation is appreciated.

Thanks.

Best Answer

Take a look at http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-magento-widget-part-1

interface Mage_Widget_Block_Interface
{
    public function toHtml();

    public function addData(array $arr);

    public function setData($key, $value = null);
}

Since both Mage_Widget_Block_Interface and Mage_Core_Block_Abstract don't seem to have a implement setTemplate method try

class Sample_WidgetOne_Block_Digg
    extends Mage_Core_Block_Abstract
    implements Mage_Widget_Block_Interface
{

    /**
     * Produces digg link html
     *
     * @return string
     */
    protected function _toHtml()
    {
        return Mage::getSingleton('core/layout')->createBlock('core/template')->setTemplate('path/to/file.phtml')->toHtml();;
    }

}
Related Topic