madzacky
madzacky

Reputation: 286

How to display static block from template file based on some condition in magento Product View page?

I want to display static block based on some condition like:

if($_product->getPrice() >= 100){
   //Static Block display code.
}
else{
   //Some other static block display code.
}

Is it possible? I don't mind displaying code the xml layout way, but I want to display the code in condition.How to do that? Please anybody can solve this?

Upvotes: 1

Views: 791

Answers (1)

Paweł Duda
Paweł Duda

Reputation: 1783

It would be something like this:

if($_product->getPrice() >= 100){
    echo $this->getLayout()->createBlock('namespace/block1')->setTemplate('namespace/block1.phtml')->toHtml();
} else {
    echo $this->getLayout()->createBlock('namespace/block2')->setTemplate('namespace/block2.phtml')->toHtml();
}

Block files need to be stored inside app/design/frontend//default/template/

In the presented case: app/design/frontend//default/template/namespace/block1.phtml

Upvotes: 3

Related Questions