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.
-
1have you tried adding it to the page.xmlLuca– Luca2015年01月19日 19:49:09 +00:00Commented Jan 19, 2015 at 19:49
-
@Unlockedluca where would one add the block on this layout page?easymoden00b– easymoden00b2015年01月19日 20:01:44 +00:00Commented Jan 19, 2015 at 20:01
2 Answers 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();;
}
}
-
1Where would I call this method? Within the widget itself?easymoden00b– easymoden00b2015年01月21日 13:28:10 +00:00Commented Jan 21, 2015 at 13:28
-
1Can you add some code to your questionMagePal Extensions– MagePal Extensions2015年01月21日 14:48:15 +00:00Commented Jan 21, 2015 at 14:48
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