Magento-从静态块解析小部件/cms声明
考虑加载静态块内容的标准Magento块。如果我想从该块中解析出任何小部件(或者就此而言,任何其他CMS声明),是否有必要构造一个方法,使标准预匹配操作类型来解析这些字符串,或者我是否能够使用内置方法获取每个声明并将其添加到我自己的数组/对象中 查看处理这些声明的正常解析的“widget/template\u filter”类,我发现链上唯一有用的方法是Varien/template.php中的protected _getIncludeParameters()方法 现在已经很晚了,所以我想明天我会更新这个问题,补充更多细节 --编辑-- 呃。。。第二天读了这篇文章,我的措辞肯定很糟糕。我责备我的女朋友 更好的表达方式是 考虑以下静态块:Magento-从静态块解析小部件/cms声明,magento,content-management-system,Magento,Content Management System,考虑加载静态块内容的标准Magento块。如果我想从该块中解析出任何小部件(或者就此而言,任何其他CMS声明),是否有必要构造一个方法,使标准预匹配操作类型来解析这些字符串,或者我是否能够使用内置方法获取每个声明并将其添加到我自己的数组/对象中 查看处理这些声明的正常解析的“widget/template\u filter”类,我发现链上唯一有用的方法是Varien/template.php中的protected _getIncludeParameters()方法 现在已经很晚了,所以我想明天我
<?php $block = Mage::getModel('cms/block')->setStoreId(Mage::app()->getStore()->getId())->load('my_static_block') ?>
<?php $content = $block->getContent() ?>
现在我只想将这个声明转换回一个对象(或者更恰当地说,我将有几个{widget}}声明,我想放入一个数组),这样我就可以检查参数值,做其他工作,等等,比如:
{{widget type="my/widget" template="my/template.phtml"}}
<?php foreach ($content->getWidgets() as $widget) : ?>
<?php echo $widget->getValue() ?>
<?php endforeach; ?>
这是我加载具有原始值或解析值的块的方式:
/**
* Implement function getStaticBlock().
*
* @return array
*/
public function getStaticBlock($blockName) {
// get the content of the block
$content=array();
if (!empty($blockName)) $content=Mage::getModel('cms/block')
->load($blockName)
->getContent();
return array($content);
}
/**
* Implement function getRenderedBlock().
*
* @return array
*/
public function getRenderedBlock($blockName) {
// get the content of the block
$content=array();
if (!empty($blockName)) $content=Mage::app()
->getLayout()
->createBlock('cms/block')
->setBlockId($blockName)
->toHtml();
return array($content);
}