title: Rendering clean & tidy HTML with TWIG templates
body: <p>I've been playing with <a href="http://twig.sensiolabs.org/" rel="noreferrer"><code>Twig</code></a> (version <code>1.9.1</code>) as a <code>PHP</code> templating engine, and I'm not totally satisfied with the rendered <code>HTML</code> as extra unwanted line-breaks and spaces are added which make the result quite untidy. To make my templates more flexible, I am using <a href="http://twig.sensiolabs.org/doc/tags/macro.html" rel="noreferrer"><code>macros</code></a> which can call each other in a nested fashion, which in itself works fine, but seems to make things worse. For instance, a <code>&lt;a&gt;</code> element is rendered as follows:</p>
  
  <pre><code>             &lt;a href="http://google.com" alt="some alternative text"&gt;                    some text with &lt;strong&gt;some html&lt;/strong&gt;
  
  
  
  &lt;/a&gt;
  </code></pre>
  
  <p>I know that part of the reason is the way my <code>twig</code> templates are formatted, as if I remove empty lines and indenting from them, the rendered <code>HTML</code> looks a bit more tidy, but not completely: <strong>the below output shows a rendered <code>&lt;a&gt;</code> with still 2 line breaks between the start and end of the element, despite the corresponding template not containing any empty lines or spaces!</strong>:</p>
  
  <pre><code>&lt;a href="http://google.com" alt="some alternative text"&gt;some text with &lt;strong&gt;some html&lt;/strong&gt;
  
  
  &lt;/a&gt;
  </code></pre>
  
  <p>Even though it helps, removing formatting from my <code>twig</code> templates (i.e. empty lines and indenting) isn't really an option as it makes my template very hard to read and maintain.</p>
  
  <p><strong>Apart from removing formatting from templates. what are the ways to render a cleaner/tidier HTML with <code>Twig</code>?</strong></p>