This is actually a question that bugged me for 8 years or so, but just swept it under the rug.
I have a project (big, old, zend 1, etc.) that contains a decent (not high but large enough) amount of logic in views. This implies existence of conditionals there. It does not have any template system (like smarty/twig) so php is used for that.
Now... my problem is how to indent (since current indentation just hurts my eyes).
Currently is like this:
<?php if ($this->product->getType() == Product_Types::BOOK) {
$bookAuthor = $this->product->getAuthor();
?>
<div><?php echo $bookAuthor; ?></div>
<?php } ?>
Basically the indentation is correct, but totally useless since I can't easily see that Some output is actually inside the if statement.
Personally I prefer this approach (and used it for years, but now I decided I need a second opinion):
<?php
if ($this->product->getType() == Product_Types::BOOK) {
$bookAuthor = $this->product->getAuthor();
?>
<div>
<?php echo $bookAuthor; ?>
</div>
<?php
}
?>
This is not actually that correct since the <?php ?>
tags don't open/close on same space. It basically creates an "pseodo-block" ?> <?php
. BUT it helps me see exactly what's where. You can see from first glance that the div belongs in the if... and I think that is actually the purpose of indenting.
How do you guys think is better? (other variants are encouraged)