Conditional statement issues with HTML
Posted: Wed Jul 15, 2009 8:26 pm
Hello all, I'm a PHP noob who's having issues with conditional statements. I ran into a problem in an include that has my navbar. I set up a simple if statement to show a selected class when that page is selected and that's working fine. However I wanted to add another condition to show a subnav and that's where the problem lies (line 13). I know about escaping quotes, but even when considering that I still can't get my code to work entirely. It's doing what I want it to, but the PHP still shows up in the source code which I know is incorrect. I've attached my code. Thanks in advance for your help.
Code: Select all
<div id="mainNav">
<ul id="navLinks">
<li><a href="/" <?php if ($varSection == "home") {echo "class=\"reverse\"";} ?>>home</a></li>
<li><a href="/services/" <?php if ($varSection == "services") {echo "class=\"reverse\"";} ?>>services</a></li>
<li><a href="/blog/" <?php if ($varSection == "blog") {echo "class=\"reverse\"";} ?>>blog</a></li>
<li><a href="/links/" <?php if ($varSection == "links") {echo "class=\"reverse\"";} ?>>links</a></li>
<li><a href="/about/" <?php if ($varSection == "about") {echo "class='selected'";} ?>>about</a></li>
<li><a href="/contact/" <?php if ($varSection == "contact") {echo "class='selected'";} ?>>contact</a></li>
</ul>
<div id="blogSubscription"><a href="/" class="linkText">Subscribe to the blog</a><a href="/"><img src="/_media/icon_RSS.gif" class="iconRSS" alt="RSS icon" /></a></div>
</div>
<!-- END id mainNav -->
<?php if ($varSection == "services") {
echo
"<div class='subnavCleaner'> </div>
<div id='subnav'>
<ul>
<li><a href='/services/' <?php if ($varSection == 'services' && $varPage == 'default') {echo 'class=\'reverse\'';} ?>>about</a></li>
<li><a href='/services/personal-liability.php' <?php if ($varSection == 'services' && $varPage == 'personalLiability') {echo 'class=\'reverse\'';} ?>>Personal Liability</a></li>
<li><a href='/services/civil-litigation.php' <?php if ($varSection == 'services' && $varPage == 'civilLitigation') {echo 'class=\'reverse\'';} ?>>Civil Litigation</a></li>
<li><a href='/services/estate-planning.php' <?php if ($varSection == 'services' && $varPage == 'estatePlanning ') {echo 'class=\'reverse\'';} ?>>Estate Planning</a></li>
</ul>
</div>";
} else {
echo "";
}
?>