Page 1 of 1

if statement syntax is wrong

Posted: Fri May 20, 2011 1:55 am
by mgason
Hi,
I am no PHP expert. I can poke about, do a little cut and paste.
Dreamweaver is telling me I have a syntax issue with my if statement. I have tried a few things without success.
Dreamweaver says the error is on the else line, that may not be true. please show me what I am doing wrong.
Thanks Mark

Code: Select all

<div class="entry-content tec-event-entry">						 
<?php /** Get the "cft_tinymce_1" custom field */
				 $block_1 = get_custom_field('cft_tinymce_1');
				if( $block_1 ) { ?>
					<?php echo $block_1; ?> 
						<?php } ?>
						<?php else { ?>
							<?php the_content(); ?>
						<?php } ?>
					</div> <!-- End tec-event-entry -->

Re: if statement syntax is wrong

Posted: Fri May 20, 2011 2:04 am
by mgason
I may have sorted it out, is this the best way, is it correct

Code: Select all

					<div class="entry-content tec-event-entry">						 
<?php /** Get the "cft_tinymce_1" custom field */
				 $block_1 = get_custom_field('cft_tinymce_1');
				if( $block_1 ) { ?>
					<?php echo $block_1; ?> 
						<?php } else { ?>
							<?php the_content(); ?>
						<?php } ?>
					</div> <!-- End tec-event-entry -->

Re: if statement syntax is wrong

Posted: Fri May 20, 2011 2:46 am
by fird01
may be u shouldn't trust dw so much.. i dont see any difference there

Re: if statement syntax is wrong

Posted: Fri May 20, 2011 3:36 am
by mgason
Hi,
yes I thought the difference is possibly still OK.

Code: Select all

<?php } ?>
                    <?php else { ?>
became this with less PHP tags

Code: Select all

<?php } else { ?>

Re: if statement syntax is wrong

Posted: Fri May 20, 2011 11:34 am
by social_experiment
fird01 wrote:may be u shouldn't trust dw so much.. i dont see any difference there
I concur with fird01.

The code sample can easily be simplified to following below. Dreamweaver probably has it's reasons for using that specific format for producing the code though (however curious).

Code: Select all

<?php 
 /** Get the "cft_tinymce_1" custom field */
 $block_1 = get_custom_field('ctf_tinymce_1');
 if ($block_1) {
 echo $block_1;
 }
 else {
  the_content();
 }
?>

Re: if statement syntax is wrong

Posted: Fri May 20, 2011 12:54 pm
by Jade
Dreamweaver does that so you can add formatting between the case statements without it having to refractor the <?php code tags so it works properly. My suggestion: don't use Dreamweaver for anything other than building the layout and do all your PHP work after the fact.