So I have added a bunch of custom attributes, and I want the title only to show up when there is a value in the custom attribute field, so for example:
When value is present, this is shown:
<h4>Ingredients</h4>
No Value:
<h4></h4>
Here is the code that I have put together, but its not working - anyone have any ideas?
You’re testing if the $_product is null there, not the attribute. Further more, you are echo-ing out that value first before attempting to output the “Product Benefits” header. (’echo’ in php prints anything to the HTML page so it becomes visible.)
Does ‘$_product->getProductBenefits()’ work or do you need to use ‘echo $_product->getResource()->getAttribute(’product_benefits’)->getFrontend()->getValue($_product)’ ??
if($_product->getProductBenefits() != 'NULL' || $_product->getProductBenefits() != '') { //test if the attribute value is null or empty echo '<h4>Product Benefits</h4>'; echo '<p>'. $_product->getProductBenefits() .'</p>'; //echo the attribute value }
Thanks for replying, Im sort of confused by your reply. Im not really sure, all I know is that the first line outputs the custom attribute, but I would like it to check to see if there is a value - and if there is nothing, then both the title and value dont show…
Where did you place this code? I’m having a hard time, where the attributes keep showing up inside the tabs even when blank. Screenshot here: Im not sure where to place the code, i.e which file?
The correct way would be to change the GetAdditionalData funtion to not return any value when value is null or return a specific value like EMPTY, then the attributes.phtml can filter out empty results, since in some cases you might want to set a value to No for a product....
sorry to say - but that’s not “beautiful”
searching for nee, no, nein, etc.. makes it hard when you enhance to more languages later. I guess the right way would be to retrieve the value of the admin store of “no” etc. But no idea how to get that one… Any hint?
It is a very bad solution indeed, but it does work, as a short term work around for my production sites,
until someone makes the effort to make a clean solution and post it ....
Here’s what I altered in attributes.phtml in order to hide product attributes that have no value:
I just added the IF statement to test for a value in the attribute. Seemed simple enough.
Hope this helps others.
It helped me, Novus! I’m now using Magento 1.7, with custom tabs on the Classic Theme from templates-master. Your code was simple and worked great. Thanks.