Magento – Magento : Call widget call from phtml file

magento-1.7magento-1.8magento-1.9programmaticallywidgets

I have created Widget and want to call it from header.phtml
enter image description here
In this widget i have called Static block but widget not called.This widget have id 2
i have set code below please help me to correct this or give me another for id = "2"

$widget = Mage::getModel('cms/widget_block')->load('2');
                    $widgetBlock = $this
                   ->getLayout()
                   ->createBlock($widget->getType(),
                                 $widget->getTitle(),
                                 $widget->getWidgetParameters());
echo $widgetBlock->toHtml();

And

<?php
$filter = new Mage_Widget_Model_Template_Filter();
$_widget = $filter->filter('{{widget type="cms/widget_page_link" template="cms/widget/link/link_block.phtml" page_id="2"}}');
echo $_widget;

?>

Best Answer

You can directly call a widget on header from admin panel create widget page.

Just click on Add Layout Update button and select page you want to display on from Display On dropdown,(here if you want to display on all page then select All Pages), then from Block Reference select Page Header (Or Page header with position) and then from Widget Options select your static block. Save the widget and check on frontend after clean cache.

Related Topic