Jump to content

Need A Little Synatax Help


nighthawk

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 } ?>

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

Wordpress actually uses the alternative structure, which is interesting...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...