IF something doesn't exist

Hi there

I’m editing some code for Magento and have a question about how to accomplish something.

I have two fields that I want to display, however on some occasions either of the fields might not be present. As a result, I need 4 conditions, but I can’t work out how to define them. Here’s the code, I shall explain more after:

[php]<?php if($_product->getRam() && $_product->getFlash()): ?>

RAM: <?php echo $_product->getResource()->getAttribute('ram')->getFrontend()->getValue($_product); ?> Flash: <?php echo $_product->getResource()->getAttribute('flash')->getFrontend()->getValue($_product); ?> <?php endif; ?>[/php]

This displays a table with both RAM and flash in. I need to know how to display tables for when either of those fields are not present. Any help much appreciated.

Thanks

Simon

try:
[php]

<?php if($_product->getRam()){ ?> RAM: <?php echo $_product->getResource()->getAttribute('ram')->getFrontend()->getValue($_product); ?> <? } if(!$_product->getFlash()){ ?> <? } if($_product->getFlash()){ ?> Flash: <?php echo $_product->getResource()->getAttribute('flash')->getFrontend()->getValue($_product); ?> <?php endif; ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service