如何通过Magento中的产品页面模板有条件地显示静态块?

时间:2013-10-24 13:52:00

标签: php xml magento

情况如下。我们有一个配置器扩展,我们希望仅在特定产品的产品页面上显示。扩展名设置为静态块。我的想法是我可以在PHP中使用if语句使用XML来定义模板。

这是我的目录XML:

<reference name="content">
    <block type="partfinder/selector" name="partfinder_selector" template="partfinder/selector.phtml"/>
</reference>

这是我在view.php文件中的PHP:

<?php
if ($_product->getSku() = 10007)
{
echo $this->getChildHtml('partfinder_selector');
}
?>

我错过了什么?现在,这只会破坏我的产品页面;所有这些。

有没有更好的方法来做我想要完成的事情?我知道以这种方式使用CMS块是不好的形式,但是,这似乎是扩展的本质。

1 个答案:

答案 0 :(得分:2)

您可以按如下方式使用:

<?php 
if ($_product->getSku() == '10007') {
    echo $this->getLayout()->createBlock('cms/block')->setBlockId('partfinder_selector')->toHtml();
}
?>

你在if语句中也错过了==。