1

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

 <?php
   $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!

2

Do this:

 <?php
   $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.

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

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.