I am trying to display a custom multiselect attribute as images on the frontend if they have been selected by the store admin.

So far I have been able to get the values "as text" on the frontend but I am not sure how I can go about associating each value with an image...

Here is what I have so far

   $multiSelectArray = $this->getProduct ()->getAttributeText('suitable_for');
   $lastItem = end ($multiSelectArray);
   foreach ($multiSelectArray as $multiSelectItem) {
   echo $multiSelectItem;
   if ($multiSelectItem != $lastItem) echo ", ";

The above code will show the values of the multiselect but I am stuck on how to associate the values with an image instead of text.

I anyone can assist I'd be very grateful!

1 Answer 1


Do this:

   $multiSelectArray = $this->getProduct ()->getAttributeText('suitable_for');
   $lastItem = end ($multiSelectArray);
   foreach ($multiSelectArray as $multiSelectItem) :?>
   <img src="/media/img/<?php echo $multiSelectItem ?>"></img>
   <?php endforeach;

and store your images in /media/img/[item].[ext], the same value as the text stored.

  • Nice approach. May be file extension (jpeg or similar) needed as well as basic file name validation.
    – Amasty
    Jul 30, 2014 at 20:53
  • Fantastic!!! Thankyou so much, I really appreciate your help... Jul 30, 2014 at 20:53
  • good one!!!!!!! Nov 11, 2018 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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