/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] if else statement?

Hey everyone. I do NOT want the following code to be executed on a page of mine called “intro”. I DO however, want the following code to be executed on all other pages on the site. I am a PHP novice. How would I write a proper if else statement to say ” IF($cpage==”intro”) Then DO NOT execute the following code and… ELSE (execute the following code) ?

Here is the “following code” that I have been talking about:

[code=php]<div id=”rightside”>

<?php if($this->showCart()) $this->cartPnl->Render(); ?>

<div style=”clear: both;”>
<?php if($this->showSideBar()) $this->sidePnl->Render(); ?>
</div>

</div>[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@Jarrod1937Mar 31.2010 — [code=php]
if($cpage !="intro"){
?>

<div id="rightside">

<?php if($this->showCart()) $this->cartPnl->Render(); ?>

<div style="clear: both;">
<?php if($this->showSideBar()) $this->sidePnl->Render(); ?>
</div>

</div>

<?php
}
[/code]


you can also do:
[code=php]
if(!$cpage == "intro"){
?>

<div id="rightside">

<?php if($this->showCart()) $this->cartPnl->Render(); ?>

<div style="clear: both;">
<?php if($this->showSideBar()) $this->sidePnl->Render(); ?>
</div>

</div>

<?php
}
[/code]
Copy linkTweet thisAlerts:
@CaptainkewlauthorMar 31.2010 — Thank you! Much appreciated!!
Copy linkTweet thisAlerts:
@CaptainkewlauthorMar 31.2010 — I did that, but now I'm getting this error:

"Parse error: syntax error, unexpected '}' in /home/scrapbk/store/templates/ga_active/index.tpl.php on line 202"

Here is the full code below. I appreciate your help:

[code=php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?= _xls_get_conf('LANG_CODE' , 'en') ?>" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= _xls_get_conf('CHARSET' , 'utf-8') ?>" />
<?php
$meta_desc = _xls_stack_pop('xls_meta_desc');

if($meta_desc){
?>
<meta name="description" content="<?= $meta_desc; ?>">
<?php
}
?><?php
$meta_keywords = _xls_stack_pop('xls_meta_keywords');

if($meta_keywords){
?>
<meta name="keywords" content="<?= $meta_keywords; ?>">
<?php
}
?><?php
$redirect = _xls_stack_pop('xls_meta_redirect');

if($redirect && isset($redirect['url']) && isset($redirect['delay'])){
?>
<meta http-equiv="refresh" content="<?= $redirect['delay']; ?>;URL=<?= $redirect['url']; ?>"/>
<?php
}
?>

<meta name="Author" content="<?= _xls_get_conf('STORE_NAME' , 'Web Store.') ?>" />
<meta name="Copyright" content="<?= _xls_get_conf('COPYRIGHT_MSG' , 'Xsilva Inc.') ?>" />
<meta name="Generator" content="Xilva Lightspeed Webstore <?= _xls_version(); ?>" />
<meta http-equiv="imagetoolbar" content="false" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<base href="<?= _xls_site_dir(); ?>/"/>

<?php global $strPageTitle; ?>
<?php if (isset($strPageTitle)): ?>
<title><?= _xls_get_conf('STORE_NAME', _sp('Shopping cart')); ?> : <?php _p($strPageTitle); ?></title>
<?php endif; ?>

<link rel="Shortcut Icon" href="favicon.ico" type="image/x-icon" />

<link rel="stylesheet" type="text/css" href="assets/css/reset.css" />
<link rel="stylesheet" type="text/css" href="<?= templateNamed('css') ; ?>/webstore.css" />
<link rel="stylesheet" type="text/css" href="assets/css/pushup.css" />

<!--[if IE]>
<script src="assets/js/ie.js" type="text/javascript"></script>
<![endif]-->

<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="<?= templateNamed('css') ; ?>/ie7.css" />
<![endif]-->

<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="<?= templateNamed('css') ; ?>/ie6.css" />
<![endif]-->

<link rel="stylesheet" type="text/css" href="assets/css/search.css" id="searchcss" />
<link rel="stylesheet" type="text/css" href="assets/css/dummy.css" id="dummy_css" />
<link rel="stylesheet" type="text/css" href="assets/css/datepicker.css" />

<script type="text/javascript">
var XLSTemplate = "<?= templateNamed(''); ?>";
</script>
</head>

<script type="text/javascript" src="assets/js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="assets/js/webstore.js"></script>
<?php $this->RenderBegin(); ?>
<script type="text/javascript" src="assets/js/pushup.js"></script>

<script type="text/javascript">
$(function() {
$("#datepicker").datepicker();
});
</script>

<!--<![endif]-->

<script type="text/javascript">
//<![CDATA[
window.onload = function () {
applesearch.init();
}
//]]>
</script>

<div id="maincontain">


<?php $this->dxLogin->Render(); ?>
<div id="container">
<div id="header">


<div id="login" class="rounded {5px bottom transparent}">
<?php if(!$this->isLoggedIn()): ?>

<div class="text">
<div class="left" style="margin: 0 55px 0 0;"><?php _p("Welcome!"); ?></div>
<div class="right"><a href="#" <?php $this->pxyLoginLogout->RenderAsEvents() ?>class="loginbox"><?php _p("Login"); ?></a> &nbsp;|&nbsp; <a href="index.php?xlspg=customer_register"><?php _p("Register"); ?></a></div>
</div>

<?php else: ?>
<div class="text"><div style="margin: 0 105px 0 0; display: block; float: left;"><a href="index.php?xlspg=myaccount"><?= _p("My Account"); ?></a></div> <?php $this->lblLogout->Render(); ?></div>
<?php endif; ?>


</div>
<a href="index.php">
<img src="<?php
$img = _xls_get_conf('HEADER_IMAGE' , false );

if(!$img)
$img = templateNamed('images') . '/webstore_installation.png';
else{
$img = _xls_get_url_resource($img);
}
echo $img;
?>" />
</a>
</div>

<div id="body">
<div id="content" class="rounded {5px top-right bottom transparent}">



<div id="nav" class="rounded {5px top transparent}">
<ul>

<li id="aboutUs"><a href="<?= _xls_custom_page_url('about') ?>"><?php _p('About Us'); ?></a></li>
<li id="products"><a href="<?= _xls_custom_page_url('products') ?>"><?php _p('Products'); ?></a></li>
<li id="promotions"><a href="<?= _xls_custom_page_url('promo') ?>"><?php _p('Promotions'); ?></a></li>
<li id="newsletter"><a href="<?= _xls_custom_page_url('newsletter') ?>"><?php _p('Newsletter'); ?></a></li>
<li id="contact"><a href="index.php?xlspg=contact_us"><?php _p('Contact'); ?></a></li>
<li id="search"><?php $this->searchPnl->Render(); ?></li>
</ul>
</div>

<?php $this->crumbTrail->Render(); ?>
</div>

<noscript>
<h1>
<?php _p('This store requires you to have a Java-Script enabled web browser. Please visit ') ; echo '<a href="www.firefox.com" target="_blank">Firefox</a>' ; _p(' to download to latest version.'); ?>
</h1>
</noscript>

<?php $this->mainPnl->Render(); ?>
</div>


if(!$cpage == "intro"){
?>

<div id="rightside">

<?php if($this->showCart()) $this->cartPnl->Render(); ?>

<div style="clear: both;">
<?php if($this->showSideBar()) $this->sidePnl->Render(); ?>
</div>

</div>

<?php
}
</div>

<div id="footer" class="rounded {5px transparent}">
<div class="left">&copy; <?php _p('Copyright'); ?> <?= date("Y"); ?> <?= _xls_get_conf('STORE_NAME' , 'Your Store') ?>. <?php _p('All Rights Reserved'); ?>.</div>
<div class="right">
<a href="<?= _xls_custom_page_url('about') ?>"><?php _p('About Us'); ?></a>
| <a href="<?= _xls_custom_page_url('tc') ?>"><?php _p('Terms & Conditions'); ?></a>
| <a href="<?= _xls_custom_page_url('privacy') ?>"><?php _p('Privacy Policy'); ?></a>
| <a href="index.php?xlspg=sitemap"><?php _p('Sitemap'); ?></a>
</div>
</div>
</div>

<!-- place google analytics here -->


<?php $this->dummy_drag_drop->Render(); ?>

<?php $this->RenderEnd(); ?>
<?php
if(QApplication::$Database[1]->EnableProfiling)
echo QApplication::$Database[1]->OutputProfiling();
?>

<script type="text/javascript">
<?php if($this->blnGetScreenRes): ?>
$.post(document.forms[0].action , { store_screen: "true", width: screen.width , height: screen.height } );
<?php endif; ?>
//done
</script>

<?php if(_xls_get_conf('DEBUG_TEMPLATE' , false)): ?>
<?php $files = array(); ?>
<!--
Template files used
<?php while($filename = _xls_stack_pop('template_used')): ?>
<?php $files[] = $filename; ?><?= $filename; ?>
<?php endwhile; ?>
-->
<?php _xls_log(sprintf(_sp("Template files used &#37;s") , implode(", " , $files))); ?>
<?php endif; ?>

<?php if($expires = _xls_page_session_expiry_duration()): ?>
<script type="text/javascript">
<?php
// in case of session expiry, reload the page so we don't get ajax/javascript errors.
// the added 5 seconds will ensure that user will be logged out due to inactivity
?>
window.setTimeout("document.location.href='<?= _xls_site_dir() ?>/index.php'" , <?= $expires ?> * 1000 + 5000 );
</script>
<?php endif; ?>
</div>
</html>[/code]
Copy linkTweet thisAlerts:
@Jarrod1937Mar 31.2010 — Thats because you pasted my code in verbatim, but i assumed you already had an open php tag before the code, always make sure you properly open and close your php tags:



</div>

[U][B]<?php[/B][/U]

if(!$cpage == "intro"){

?>

<div id="rightside">

<?php if($this->showCart()) $this->cartPnl->Render(); ?>

<div style="clear: both;">
<?php if($this->showSideBar()) $this->sidePnl->Render(); ?>
</div>

</div>


<?php

}

[U][B]?>[/B][/U]

</div>

<div id="footer" class="rounded {5px transparent}">
Copy linkTweet thisAlerts:
@CaptainkewlauthorMar 31.2010 — Thanks bud! Not getting an error now.

Cheers,
×

Success!

Help @Captainkewl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...