开发者

Magento - adding a widget instance to a template file

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?


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"}}');
?>


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


To know the correct parameters "type", "template" and more, you can use the "Insert widget" button on the graphical editor in a block/page template, then you click the show/hide editor and you get the code


The answer above may work, but the same thing can be achieved by loading the widget as you would a static block and passing in the custom parameters using the magic setters like this:

<?php echo $this->getLayout()->createBlock('cms/widget_page_link')->setTemplate('cms/widget/link/link_block.phtml')->setPageId(2); ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜