0

I want the following to display only if there is a value for this field in the database:

<p>Available Colors: <?php  echo $_additional["color_spec"]["value"]; ?></p>

What I had attempted does not work:

<?php if ($color_spec = $_product->getcolor_spec());
if (trim($color_spec)) {
    echo 'Men / Women: ' . $this->htmlEscape($color_spec);
}
2
  • if that attribute have yes then only display right
    – Magento 2
    Oct 5, 2015 at 16:52
  • yes, that is what I'm needing to do. Thank you! Oct 5, 2015 at 21:24

1 Answer 1

1

If it's yes or no attribute use this

<?php if ($_product->getAttributeText('freeshipping')=='Yes') { ?>
    <li><?php echo "Free Shipping"; ?></li>
<?php } else { ?>
    <li><?php echo "No Free Shipping"; ?></li>
<?php } ?>

if it's text box use this

$attribute = $_product->getResource()->getAttribute('emi');
$attribute_value = $attribute ->getFrontend()->getValue($_product);
if ($attribute_value) {
    echo "EMI Start With: " ."Rs.". $attribute_value;
}
1
  • the first use would not work because it needs to show what's in the db for that value. The second one still shows: Available Colors: No. If there are no available colors in the db for that item, I do not want it to echo anything at all. Oct 12, 2015 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.