您好我正在尝试使用属性值作为静态块标识符。
我有一个名为designer
的属性。在产品页面的标签中,我想根据此属性的值显示静态块
echo $this->getLayout()->createBlock('cms/block')->setBlockId('**designer**')->toHtml();
所以我希望设计师能够替换特定产品的价值,所以如果我有一个属性值为designer-1
的产品,我希望它是
echo $this->getLayout()->createBlock('cms/block')->setBlockId('designer-1')->toHtml();
等等
答案 0 :(得分:0)
如果您在模板中输出此内容(查看产品页面时):请尝试以下操作:
$product = Mage::registry('current_product');
$attributeText = $product->getAttributeText('designer');
//For uniformity of block identifiers, make it all lower case and make sure you are using lower case as block name
$lowerCaseValueForBlockId = strtolower($attributeText);
$cmsBlock = Mage::getModel('cms/block')->load($lowerCaseValueForBlockId);
if ($cmsBlock->getId()) {
echo $this->getLayout()->createBlock('cms/block')->setBlockId($lowerCaseValueForBlockId)->toHtml();
//Or you can use below code
echo $cmsBlock->getContent();
}