0

I have a custom tab on the product page which at the moment shows a static block.

What I need it to do is to show a different static block based on the text of an attribute.

For example, the tab will show a phtml file checking the text of a custom attribute then displaying the correct static block.

3
  • Your custom attribute type is drop-down or text? – Akhilesh Patel Oct 7 '15 at 17:33
  • Drop down but can be changed if needed – Mike Tim Turner Oct 7 '15 at 17:37
  • What have you tried so far? Any code you could share with us or a certain specific issue you run into? – Sander Mangel Oct 7 '15 at 17:56
0

As per your requirement you will need to create number of static blocks same as your drop-down values.

Now for example you have drop-down attribute values test1,test2,test3 etc...

Create your static blocks with identifier static_blick_test1, static_blick_test2, static_blick_test3 etc...

Now in your phtml file you must have current product object and you can call it like.

<?php $attributeValue = strtolower($product->getAttributeText('custom_attribute_code')); ?>

Now based on this attribute value create your static block identifier like

<?php $staticBlockIdentifier = "static_block_".$attributeValue; ?>

Now you can call this static block like

<?php echo $this->getLayout()->createBlock("cms/block")->setBlockId($staticBlockIdentifier)->toHtml();?>

This way you can call your static block dynamically as per your custom attribute value in your product tab.

3
  • So I put all 3 in the phtml file? What do you mean current product object? Sorry :s – Mike Tim Turner Oct 7 '15 at 18:11
  • $product = Mage::registry('çurrent_product'); or your file should have block 'catalog/product_view' – Akhilesh Patel Oct 7 '15 at 18:25
  • You helped a lot, thank you. you have a typo though it should be $product = Mage::registry('current_product'); – Mike Tim Turner Oct 7 '15 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.