View Full Version : display:none in PHP?
viktor
06-20-2008, 08:16 AM
I'm trying to figure out if there's anything that works like display:none but in PHP. It's module for Joomla.
I'm using IF..ELSE statement and I want to be able to hide/disable the code for ELSE. It's a shopping cart, I'm trying to hide it when it's empty, and when something is in the basket then it shows up. This is the code for the shopping cart.
<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
if(!$vmMinicart) { ?>
<hr>
<?php } ?>
<div style="float: left;" >
<?php echo $total_products ?>
</div>
<div style="float: right;">
<?php echo $total_price ?>
</div>
<?php if (!$empty_cart && !$vmMinicart) { ?>
<br/><br style="clear:both" /><div align="center">
<?php echo $show_cart ?>
</div><br/>
<?php }
echo $saved_cart;
?>
I would appreciate any help.
v1ktor
allahverdi
06-20-2008, 10:05 AM
<?php
if($myshoppingcard != ""){
?>
//your shopping card here
<?php
}
else{
?>
//If it is emtpy here
<?php
}
?>
I don't know if it is correct way or not. But you can try it :)
boogyman
06-20-2008, 12:56 PM
<?php if (!$empty_cart && !$vmMinicart) { ?>
<br/><br style="clear:both" /><div align="center">
<?php echo $show_cart ?>
</div><br/>
<?php }
will only write out that html code if the shopping cart exists
djr33
06-20-2008, 02:25 PM
PHP is a way of writing html. Thus, decide what the html should be, and all you need to do after that is write the PHP to make that show up.
The solutions above make sense to me, but if you want to use display none, that's possible too.
<sometag style="<?php if (!condition) { echo 'display:none;'; } ?>">
viktor
06-20-2008, 09:04 PM
Thanks for quick replies.
Here's what I did, but I'm getting an error code:
<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
<?php if (!$empty_cart && !$vmMinicart) { ?>
<br/><br style="clear:both" /><div align="center">
<?php echo $show_cart ?>
</div><br/>
<?php }
else (!$vmMinicart) { ?>
<hr>
<?php } ?>
<div style="float: left;" >
<?php echo $total_products ?>
</div>
<div style="float: right;">
<?php echo $total_price ?>
</div>
<?php }
echo $saved_cart;
?>
And the error is :
Parse error: syntax error, unexpected '<' in .../default/templates/common/minicart.tpl.php on line 3
Where did I mess up integrating piece of code?
v1k
This should work:
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
if (!$empty_cart && !$vmMinicart) { ?>
<br/><br style="clear:both" /><div align="center">
<?php echo $show_cart ?>
</div><br/>
<?php }
else (!$vmMinicart) { ?>
<hr>
<?php } ?>
<div style="float: left;" >
<?php echo $total_products ?>
</div>
<div style="float: right;">
<?php echo $total_price ?>
</div>
<?php }
echo $saved_cart;
?>
Your problem was you had a <?php in the middle of a php code. :)
viktor
06-20-2008, 09:43 PM
Thanks Nile, but I still got error code:
Parse error: syntax error, unexpected '{' in .../default/templates/common/minicart.tpl.php on line 11
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
if (!$empty_cart && !$vmMinicart) { ?>
<br/><br style="clear:both" /><div align="center">
<?php echo $show_cart ?>
</div><br/>
<?php
}else
if (!$vmMinicart) { ?>
<hr>
<?php } ?>
<div style="float: left;" >
<?php echo $total_products ?>
</div>
<div style="float: right;">
<?php echo $total_price ?>
</div>
<?php }
echo $saved_cart;
?>
viktor
06-20-2008, 09:58 PM
Ahhhhh another one...
Parse error: syntax error, unexpected '}' in .../default/templates/common/minicart.tpl.php on line 21
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
if (!$empty_cart && !$vmMinicart) { ?>
<br/><br style="clear:both" /><div align="center">
<?php echo $show_cart ?>
</div><br/>
<?php
}else
if (!$vmMinicart) { ?>
<hr>
<?php } ?>
<div style="float: left;" >
<?php echo $total_products ?>
</div>
<div style="float: right;">
<?php echo $total_price ?>
</div>
<?php
echo $saved_cart;
?>
This should work.
viktor
06-20-2008, 10:11 PM
No error messages, but empty shopping cart is still displayed.
allahverdi
06-21-2008, 12:51 PM
Check your $empty_cart and $vmMinicart, i think problem are in them 100%.
Paste that variables here if u want.
Just got another way:
<?php
if (!$empty_cart && !$vmMinicart) {
$display = "display:none";
}
else{
$display = "";
}
//here goes your card
<div style="<?php echo $display; ?>"></div>
?>
NOTE: This won't work on you again too. First problem is in your variables.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.