2

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.

2
  • 1
    have you tried adding it to the page.xml
    – Luca
    Jan 19, 2015 at 19:49
  • @Unlockedluca where would one add the block on this layout page? Jan 19, 2015 at 20:01

2 Answers 2

2

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();;
    }

}
2
  • 1
    Where would I call this method? Within the widget itself? Jan 21, 2015 at 13:28
  • 1
    Can you add some code to your question Jan 21, 2015 at 14:48
3

In the widget.xml you define with the typeattribute the block class of the widget. For example type="catalog/category_widget_link"refers to the block class Mage_Catalog_Block_Category_Widget_Link. It's important that the block class extends Mage_Core_Block_Template and implements Mage_Widget_Block_Interface. Finally in that block class you could set the template by defining:

`$this->setTemplate('catalog/product/widget/new/content/new_grid.phtml');`

For more detailed information please provide some code snippets. And you should definitely work your way through these articles:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.