php inside html indent style 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:

  &lt;?php if ($this-&gt;product-&gt;getType() == Product_Types::BOOK) {
       $bookAuthor = $this-&gt;product-&gt;getAuthor();
  ?&gt;
  &lt;div&gt;&lt;?php echo $bookAuthor; ?&gt;&lt;/div&gt;
  &lt;?php } ?&gt;


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):

  &lt;?php
     if ($this-&gt;product-&gt;getType() == Product_Types::BOOK) {
        $bookAuthor = $this-&gt;product-&gt;getAuthor();
        ?&gt;
           &lt;div&gt;
              &lt;?php echo $bookAuthor; ?&gt;
           &lt;/div&gt;
        &lt;?php
     }
  ?&gt;


This is not actually that correct since the &lt;?php ?&gt; tags don't open/close on same space. It basically creates an "pseodo-block" ?&gt; &lt;?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)
The second one is definitely better. In the first one, it's really hard to see that the div is actually inside the if. 

Personally, I would build the string completely in PHP, and then echo it, instead of switching in and out of the HTML context. This will avoid the opening and closing PHP tags being littered around your code:

$html = "";
if ($this-&gt;product-&gt;getType() == Product_Types::BOOK) {
    $html += "&lt;div&gt;" . $this-&gt;product-&gt;getAuthor() . "&lt;/div&gt;";
}
echo $html;