I want to create an multiselect attribute with 3 values. When I select the values during product creation It should display the content from the static blocks. So I entered the identifier of the static block under default store view (which is English below) option during attribute creation like:

enter image description here

Now in view.phtml, I have added the below code:

echo $this->getLayout()->createBlock('cms/block')->setBlockID($cmsstatic)->tohtml();

where r_n is the attribute code.

But am getting error like:

Fatal error: Call to undefined function getResource()

Kindly someone help me to resolve this issue.

3 Answers 3


Try this

For select attribute

<?php $attributeValue = $_product->getAttributeText('r_n');?>
<?php if($attributeValue):?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockID($attributeValue)->tohtml(); ?>
<?php endif;?>

For multiselect attribute

<?php $attributeValues = $_product->getAttributeText('r_n');?>
<?php if(is_array($attributeValues) & !empty($attributeValues)):?>
<?php foreach($attributeValues as $attributeValue):?>
    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockID($attributeValue)->tohtml(); ?>
<?php endforeach;?>
<?php elseif($attributeValues):?>
    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockID($attributeValues)->tohtml(); ?>
<?php endif;?>
  • I used your multiselect attribute code & i get error like "Call to undefined function getAttributeText()"
    – Ramya
    Jul 22, 2016 at 12:42
  • hey your code has very small syntax error: $_product>getAttributeText('r_n') The arrow is not proper. It should be like : $_product->getAttributeText('r_n') Now its perfectlyy working. Thank you.
    – Ramya
    Jul 22, 2016 at 12:46
  • @Ramya U r right and updated ans pls check now
    – Abdul
    Jul 22, 2016 at 13:02

In order to get the option label of an attribute value of the current product in catalog/product/view.phtml you can also use:


Before getResource() you need to use object of class in which this function has been created.

For example if you are trying to get value of a product attribute, then it should be:

  • Can you explain briefly?
    – Ramya
    Jul 22, 2016 at 12:08
  • Please check my modified answer. Jul 22, 2016 at 12:14

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.