Template Files - PHP or HTML I notice most (if not all) templates are written in HTML with PHP snippets where required.

I've been writing a few PHP heavy templates, and instead of writing HTML and encasing almost every line in  tags, I have opted for writing PHP, using the print function to render HTML.

Is there any reason I should be writing in mostly HTML instead?

I imagine there's more overhead using PHP to render the HTML, but is there enough to worry about?

Second to that, is there any reason templates encase every line in  tags instead of just the opening and closing tags are required?

e.g.

&lt;?php if($a == $b) {?&gt;
   &lt;?php print 'a equals b';?&gt;
&lt;?php } else {?&gt;
   &lt;?php print 'a does not equal b';?&gt;
&lt;?php } endif;?&gt;


vs

&lt;?php if($a == $b) {
   print 'a equals b';
 } else {
   print 'a does not equal b';
 } endif;?&gt;
Overhead, if there is any, is of little concern. This is pretty much a stylistic concern. As such, the important part is a consensus among developers so there is clear readability expectations.

drupal.org has documentation when it comes to template coding standards. In this case, little-as-possible PHP tags usage is preferred (the concern here is readable HTML rendering, not code execution) with use of PHP's alternative control structure:

&lt;?php if ($a == $b):?&gt;
   a equals b
&lt;?php else: ?&gt;
   a does not equal b
&lt;?php endif; ?&gt;


See the documentation for further style guidelines with templates.