0

I have a multi select attribute with some values. I get the values with this code:

<?php $targetValue = explode(",", $_product->getResource()->getAttribute('nf_allergie')->getFrontend()->getValue($_product)); ?> <?php if(count($targetValue) > 0 ): ?> <?php foreach($targetValue as $key=>$val): ?> <div class="<?php echo $key ?>"> <span> <?php echo $val ?> </span> </div> <br> <?php endforeach; ?> <?php endif;?> 

For example some values: - Gluten - Mosterd - Noten - Schaaldieren

How can I check if the value is Gluten, then show Gluten.jpg. And if also Mosterd is selected, then show also Mosterg.jpg

How can I achieve such thing?

3
  • Possible duplicate of Magento multiple selection attribute Commented Jun 22, 2017 at 14:33
  • Yes but the question was a little bit different, this is only for checking if a value is, then show this. Commented Jun 22, 2017 at 14:42
  • Do you want to show images instead of labels? Commented Jan 24, 2019 at 10:48

1 Answer 1

0

Easy Method - Keep your images in media location or skin location in Magento, with these names.

I believe these labels are fixed.

<?php $targetValue = explode(",", $_product->getResource()->getAttribute('nf_allergie')->getFrontend()->getValue($_product)); ?> <?php if(count($targetValue) > 0 ): ?> <?php foreach($targetValue as $key=>$val): ?> <div class="<?php echo $key ?>"> <span> <img src="skinurl/<?php echo $val ?>.jpg > </span> </div> <br> <?php endforeach; ?> <?php endif;?> 

Another Method - Upload image with attribute options values.

Please read this tutorial for more details http://www.bubblecode.net/en/2012/02/05/magento-add-images-to-product-attribute-options/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.