问题描述
快速概览:我正在尝试将一组特定静态块的结果返回到一个 phtml 文件(然后从 cms 页面调用该文件)) 在 Magento 中.
注意:我一直在谷歌上搜索,有些答案让我比其他答案更接近,但我尝试过的任何东西似乎都没有 100% 有效?
详情:
我已经有一组特定的静态块,它们都以 testimonial- 的标识符开头.例如,每个静态块是这样的:testimonial-1、testimonial-2、testimonial-3等等.我的开发站点上总共有 5 个(更多在实时站点上,但在此处无关紧要).
我有一个 CMS 页面,其中包含 name.phtml 文件中的代码(我的 phtml 文件的位置在这里:app/design/frontend/[包]/[模板]/模板/页面/):
{{block type="core/template" template="page/name.phtml" title="Others Say:" identifier="testimonial-"}}
这是我的 .phtml 文件代码:
getCollection()->addFieldToFilter('identifier', array('like'=>'testimonial'.'%'))->addFieldToFilter('is_active', 1);//获取计数$blockCount = $collection->count();echo '块计数:'.$blockCount .'<br/>';//仅用于测试$blockNum = 1;foreach($collection as $key => $value){$_blockId = $this->getIdentifier();$block_ID = $_blockId .$blockNum;回声键:".$key .——".块ID:".$block_ID ."<br/>";$blockNum++;}$_block = $this->getLayout()->createBlock('cms/block')->setBlockId($block_ID);如果($_block):?><div class="block block-testimonial"><div class="block-title"><strong><?php echo $this->getTitle();?></strong>