0
app/design/frontend/default/theme/template/catalog/product/view/attributes.phtml

http://pastebin.com/6uzYgauE

this is the attributes.phtml file we are using to display the attibutes in frontend.

suppose if attribute value is empty , than thiose attributes will not display in frontend for the

particular product.

but if we give some empty space in the attribute text field, than those attributes are displaying in the frontend.

if we gave empty space as attribute values , than we want to hide those attributes for the particular product.

ex: if attribute color = "" than color will not display in frontend

if attribute color = " " than color will display in frontend. we want to hide color here....

please help me to find solution.

  • <?php $attribute = $_product->getResource()->getAttribute('attriute_id'); $attribute_value = $attribute ->getFrontend()->getValue($_product); if ($attribute_value) { echo "$attribute_value"; } ?> – Magento 2 Sep 22 '15 at 9:09
  • in which line i have to place the above code ? – Baby in Magento Sep 22 '15 at 9:09
  • all the line to fetch particular attribute – Magento 2 Sep 22 '15 at 9:10
  • <?php $attribute = $_product->getResource()->getAttribute('color'); $attribute_value = $attribute ->getFrontend()->getValue($_product); if ($attribute_value) { echo "$attribute_value"; } ?> – Magento 2 Sep 22 '15 at 9:12
  • i want to hide the attribute which is having empty values..... – Baby in Magento Sep 22 '15 at 9:15
1

to hide empty spaces in the attribute values, you can use the below code in the attributes.phtml file.

$attribute_value = 'xyz';
if (strlen($attribute_value) > 0)
{
   // code to display the value
}
  • i am getting syntax error at this line : if (strlen($attribute_value) > 0) please check here : pastebin.com/jX0ZhsSr i added your code at the end – Baby in Magento Sep 22 '15 at 9:26
  • 1
    i forgot a semi-column at the end. check the updated answer – Manashvi Birla Sep 22 '15 at 9:31
  • glad to help you :) – Manashvi Birla Sep 22 '15 at 9:57
  • hi sorry, i checked for wrong product, its not working.... pastebin.com/EvtiGQRU – Baby in Magento Sep 22 '15 at 10:03
  • y are u putting this code at the end of the file. place this code where the attribute value is printed. also i have assumed a randaom xyz value. dnt use this – Manashvi Birla Sep 22 '15 at 10:09

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.