Displaying contacts in PHP, with options to omit some information
The answers you'll get will be highly opinion-based, I guess. So, here a few points in favor of the first type of templating as the approach of inserting short PHP-elements into the template has some advantages.



Easier to read and follow

For a developer, the latter approach might be easier to follow. But often it's important to understand the structure and hierarchy of the markup. Your approach makes it quite hard:


echo '&lt;h1&gt;'. $this-&gt;escape($tparams-&gt;get('page_heading')) . '&lt;/h1&gt;';
echo '&lt;div class="page-header"&gt;';
echo '&lt;h2&gt;';
if ($this-&gt;item-&gt;published == 0){
    echo '&lt;span class="label label-warning"&gt;' . JText::_('JUNPUBLISHED') . '&lt;/span&gt;';
}
echo '&lt;span class="contact-name" itemprop="name"&gt;'. $this-&gt;contact-&gt;name . '&lt;/span&gt;';
echo '&lt;/h2&gt;';
echo '&lt;/div&gt;';



It looks like everything is on one level and only the span-element is nested. This might be ok for a short passage like we see here. But consider a complex component with lots of nested elements.

Somebody who understands HTML can maintain the template

The first point brings us straight to this: A fronted-developer, who is not familiar with PHP can maintain and update your template. Taking the example from above, the person knows easily where to adjust the code, without breaking anything, if it would be written like this:

&lt;h1&gt;&lt;?=$this-&gt;escape($tparams-&gt;get('page_heading'))?&gt;&lt;/h1&gt;
&lt;div class="page-header"&gt;
  &lt;h2&gt;
    &lt;span class="label label-warning"&gt;&lt;?=($this-&gt;item-&gt;published ? JText::_('JUNPUBLISHED') : '')?&gt;&lt;/span&gt;
    &lt;span class="contact-name" itemprop="name"&gt;&lt;?=$this-&gt;contact-&gt;name?&gt;&lt;/span&gt;
  &lt;/h2&gt;
&lt;/div&gt;


Also removing parent wrappers or inserting new elements is much easier.

Too much logic in the templates

I would say, that with the latter approach one might tend to include too much logic into the template. "Oh, I forgot to load the all products and categories from the database. Well, I'll just include it right here." And yes, this could happen with the first approach as well:


&lt;?php elseif ($show_contact_category === 'show_with_link') : ?&gt;
    &lt;?php $contactLink = ContactHelperRoute::getCategoryRoute($this-&gt;contact-&gt;catid); ?&gt;



This should happen somewhere in the controller or any other part before the template. However, I find it easier, to keep logic out of the presentation layer, if I'm filling and not creating a template.

Help from the IDE

Your IDE will find problems in the template, like unclosed elements, if you're actually writing HTML instead of creating strings containing HTML.

Switching to a different template engine or even language

At some point you might want to switch from PHP templating to a template engine  like Twig or Moustache. It's way easier when you have everything ready for this:

&lt;h1&gt;&lt;?=$this-&gt;escape($tparams-&gt;get('page_heading'))?&gt;&lt;/h1&gt;


Can easily become this in Twig – as it automatically escapse strings:

&lt;h1&gt;{{ page_heading }}&lt;/h1&gt;


Or if you switch to Moustache you aren't even coupled to PHP anymore. You could use your template with a lot of other languages. Or you might even want to include the template in a native APP in the future.