Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - adding a widget instance to a template file

Tags:

magento

I know that you can call a cms block directly from a template file using the following:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_links')->toHtml() ?>

Is there some way to do this with widget instances?

like image 419
Marlon Creative Avatar asked Jul 01 '26 08:07

Marlon Creative


2 Answers

In your template:

<?php
$filter = Mage::getModel('widget/template_filter');
echo $filter->filter('{{widget type="cms/widget_page_link" template="cms/widget/link/link_block.phtml" page_id="2"}}');
?>
like image 74
Japhet Perez Atristain Avatar answered Jul 03 '26 16:07

Japhet Perez Atristain


Andrew missed toHtml() function at the end:

<?php echo $this->getLayout()->createBlock('cms/widget_page_link')->setTemplate('cms/widget/link/link_block.phtml')->setPageId(2)->toHtml(); ?>
like image 36
Sonia Simina Avatar answered Jul 03 '26 16:07

Sonia Simina



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!