Magento-将小部件实例添加到模板文件
我知道您可以使用以下命令直接从模板文件调用cms块:Magento-将小部件实例添加到模板文件,magento,Magento,我知道您可以使用以下命令直接从模板文件调用cms块: <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_links')->toHtml() ?> 有什么方法可以通过小部件实例实现这一点吗 在模板中: <?php $filter = Mage::getModel('widget/template_filter'); echo $filter->
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_links')->toHtml() ?>
有什么方法可以通过小部件实例实现这一点吗 在模板中:
<?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"}}');
?>
要知道正确的参数“type”、“template”等,您可以在块/页面模板中使用图形编辑器上的“Insert widget”按钮,然后单击显示/隐藏编辑器,得到代码,上面的答案可能有效,但是,通过像加载静态块一样加载小部件并使用如下魔术设置器传入自定义参数,也可以实现同样的效果:
<?php echo $this->getLayout()->createBlock('cms/widget_page_link')->setTemplate('cms/widget/link/link_block.phtml')->setPageId(2); ?>
Andrew在结尾处错过了toHtml()函数:
<?php echo $this->getLayout()->createBlock('cms/widget_page_link')->setTemplate('cms/widget/link/link_block.phtml')->setPageId(2)->toHtml(); ?>
Great-获取一个产品链接:在1.8.1中似乎不起作用,$\u widget=$filter上的代码中断。。。奇怪的是,这对我来说在法师1.6.2.0上不起作用,但雅弗的回答是这样的