Magento Forum

   
if else construction
 
Paul-xib
Sr. Member
 
Avatar
Total Posts:  116
Joined:  2009-02-02
The Netherlands
 

i have a question about the if else function.

I am still a php beginner so this question may be very easy but i don’t know how to fix it smile

i am looking at the product view.phtml and saw this code:

<?php if ($_additional $this->getChildHtml('additional')):?>
            
<div class="collateral-box">
                <
div class="head">
                    <
h4><?php echo $this->__('Additional Information'?></h4>
                </
div>
                
<?php echo $_additional ?>
            
</div>
        
<?php endif;?>

this says: if there is additional information show it inside a div. if not don’t show it. right?

How can i turn this code into this:

if there is additional information show it inside a div. if not show the message “No information”.

Hope it would make sense. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
magentoassist
Guru
 
Avatar
Total Posts:  528
Joined:  2008-11-19
 

A php if-else statement is generally formed like this:

<?php if (condition): ?>
     
//do something
<?php elseif (condition): ?>
     
//do something
<?php else: ?>
     
//do something
<?php endif;?>

To do what you’re asking, you’d add an “else” condition prior to the “endif” and then put your “no information” text after the else statement.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Paul-xib
Sr. Member
 
Avatar
Total Posts:  116
Joined:  2009-02-02
The Netherlands
 

k thx. it works now smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top