Jump to content

Need A Little Synatax Help


nighthawk
 Share

Recommended Posts

I have an if else statement to control display (or not) a column. The if else functions properly, but when the code is executed the "else" (actual text) is displayed on the webpage, in both conditions. Code is below

<?php if($this->countModules('left')) : ?>			<div id="left_col" class="clearfix">				<jdoc:include type="modules" name="left" style="xhtml"/>			</div>			  else				<div id="left_col_noModules"></div>		<?php endif; ?>

Maybe the html tags are messing it up?

Link to comment
Share on other sites

I have an if else statement to control display (or not) a column. The if else functions properly, but when the code is executed the "else" (actual text) is displayed on the webpage, in both conditions. Code is below
<?php if($this->countModules('left')) : ?>			<div id="left_col" class="clearfix">				<jdoc:include type="modules" name="left" style="xhtml"/>			</div>			  else				<div id="left_col_noModules"></div>		<?php endif; ?>

Maybe the html tags are messing it up?

"endif" isn't a PHP statement. It's from BASIC and other similar languages.In PHP you use braces:
<?php if($this->countModules('left')) { ?>  <div id="left_col" class="clearfix">    <jdoc:include type="modules" name="left" style="xhtml"/>  </div><?php }  else { ?>  <div id="left_col_noModules"></div><?php } ?>

Edited by Ingolme
Link to comment
Share on other sites

PHP does support the alternate syntax in flow structures, which provides for a colon and something like endif in place of opening and closing braces -- so that part of the original script was okay. (PHP borrows a few items from other languages.)The trouble was placing the else clause outside the <?php ?> tags.Realistically, though, Ingolme's solution is best, simply because the huge majority of PHP authors use the braces.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...