|
Posted by Toby Inkster on 01/18/07 12:57
Kimmo Laine wrote:
> <?php if (bShowBlock){ ?>
>
> LARGE BLOCK OF HTML
>
> <?php } else { ?>
>
> SOME OTHER LARGE BLOCK OF HTML
>
> <? } ?>
Personally, I've never found that very aesthetically pleasing. I prefer
things between '<?php' and '?>' to seem to make sense on their own (even
if they do, say, access functions or variables defined elsewhere).
Slightly nicer looking are:
<?php
include (bShowBlock ? 'foo.html' : 'bar.html');
?>
or, if you don't want to have the blocks of HTML stored in external files,
you could use output buffering, like so:
<?php
ob_start();
?>
LARGE BLOCK OF HTML
<?php
$foo = ob_get_clean();
ob_start();
?>
SOME OTHER LARGE BLOCK OF HTML
<?php
$bar = ob_get_clean();
print (bShowBlock ? $foo : $bar);
?>
However, if the "large blocks of HTML" actually contain some PHP code, be
aware that the latter of these two will execute both sets of code fully.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|