PHP Help Needed! Hiding custom attributes using 'IF" statement etc.

by 5 replies
6
I am trying to hide 'no value' custom attributes on my magento frontend.

I am wondering if there is a way to hide the entire code if the 'singer' field (including attribute title) is emtpy on my magento backend?

I found a couple solutions online, i was able to hide the attribute value itself, but not the <b>Singer:</B> It seems to show no matter what.

This is what I have so far:

Thanks in advance.
#programming #statement
  • Have you tried putting both items in a PHP echo call, and placing the echo calls inside a bracketed if statement?

    I can't think of any reason that such an approach wouldn't work.

    Good luck.
  • sorry but I m really noob at this.
    If its possible, can someone please modify my original code accordingly

    Thank you very much in advance.
  • well it depends on what is the value that corresponds to empty, is it ""?

    if so, you can try

    if(!empty($_product->getResource()->getAttribute('singer')->getFrontend()->getValue($_product)))
    {
    ?>
    <b>Singer:</b> <?php echo $_product->getResource()->getAttribute('singer')->getFrontend()->getValue($_product) ?><br />
    <?php
    }
  • The <b>Singer:</b> is going to show no matter what. It's not within the php code. It's part of your html. So no matter what goes on with your script, the html will show up.
  • I got that going. Thanks guys.

    Now i am experiencing something different;

    This is what I have right now on my frontend (magento)- product view;

    Code:
    <?php echo "<b>Edition:</b> ".()->getAttributeText('edition')>
    it is a custom attribute (drop down) with 3 choices;
    Edition 1
    Edition 2
    Edition 3

    I would like to make it possible so that if "edition 1" is selected on backend, it will show an image.

    How can I possibily achieve something like that?

    Thanks again

Next Topics on Trending Feed