Question

This My Code

$IsCustomizableColor =  $_product->getResource()->getAttribute('customizecolor')->getFrontend()->getValue($_product);
   <?php 
$SplitColor = explode (',', $IsCustomizableColor);
foreach($SplitColor as $color){?>
 <?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'Custom/'.$color.'.png'; ?>
<?php } ?>

it will print with space for second time first time it's fine

my output

http://localhost/Test/media/Custom/Black.png 
http://localhost/Test/media/Custom/ Green.png 
http://localhost/Test/media/Custom/ Yellow.png

what is the problem? How to fix this

Was it helpful?

Solution

Replace your code with this :

$IsCustomizableColor =  $_product->getResource()->getAttribute('customizecolor')->getFrontend()->getValue($_product);
   <?php 
$SplitColor = explode (',', $IsCustomizableColor);
foreach($SplitColor as $color){?>
 <?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'Custom/'.trim($color).'.png'; ?>
<?php } ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top