MacOfAges
MacOfAges

Reputation: 39

How can I display a static block conditionally by way of product page template in Magento?

Here is the situation. We have a configurator extension that we would like to feature on the product page of only specific products. The extension is set up as a static block. My thought was that I could use an if statement in PHP using XML to define the template.

Here is my catalog XML:

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

This is my PHP in the view.php file:

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

What am I missing? Right now, this just destroys my product pages; all of them.

Is there a better way to do what I am trying to accomplish? I know it is bad form to use CMS blocks this way, however, that seems to be the nature of the extension.

Upvotes: 0

Views: 1855

Answers (1)

Sunil Verma
Sunil Verma

Reputation: 2500

You can use as follows :

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

you also missed == in your if statement.

Upvotes: 2

Related Questions