Title pretty much says it all. I'm trying to output a static block with the same ID as the attribute value, however my code is only outputing the FIRST attribute value.
The following code is in view.phtml and is outputing the first static block of the 5 multiselect values selected.
Any help is greatly appreciated!!!
<?php
$cmsstatic = $_product->getResource()->getAttribute('collection1')->getFrontend()->getValue($_product);
$blockids = explode(",", $cmsstatic);
foreach($blockids as $kry=>$value)
{
echo $this->getLayout()->createBlock('cms/block')->setBlockID($value)->tohtml();
}
?>
The issue here is that your $value
block IDs are wrong. Take a look at the output from $_product->getResource()->getAttribute('collection1')->getFrontend()->getValue($_product)
and you will probably notice it actually looks something like this: collection3, collection6
. Notice the spaces after the commas. When you run explode(",", $cmsstatic)
you are getting the spaces in your resulting array. Since the first block ID contains no extra spaces, it is valid, but none of the following ones will be.
explode(", ", $cmsstatic)
$this->getLayout()->createBlock('cms/block')->setBlockId(trim($value))->toHtml()