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

5 replies
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:

<b>Singer:</b> <?php echo $_product->getResource()->getAttribute('singer')->getFrontend()->getValue($_product) ?><br />
Thanks in advance.
#statement
  • Originally Posted by Noobcorp View Post

    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.
    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.
    Signature

    Bros find strictly platonic dudes on seekBromance.com
    _______________________________________________
    "It's pretty simple. You work hard, you believe anything is possible, and you try to make the world better."

    {{ DiscussionBoard.errors[6772101].message }}
  • Profile picture of the author Noobcorp
    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.
    {{ DiscussionBoard.errors[6772244].message }}
  • Profile picture of the author tomm
    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
    }
    {{ DiscussionBoard.errors[6772409].message }}
  • Profile picture of the author dudeontheweb
    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.
    Signature

    Need a QR Code? Check out my QR Code Generator. It's FREE!

    {{ DiscussionBoard.errors[6784358].message }}
  • Profile picture of the author Noobcorp
    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
    {{ DiscussionBoard.errors[6787745].message }}

Trending Topics