title: PHP templates - with PHP
body: <p>What's the most elegant templating (preferably in pure PHP!) solution you've seen?</p>
  
  <p>Specifically i'm interested in handling:</p>
  
  <ol>
  <li>Detecting in a repeating block whether it's the first or last element</li>
  <li>Easy handling of odd/even cases, like a zebra striped table, or similar</li>
  <li>Other modulos logic, where you'd do something every n'th time.</li>
  </ol>
  
  <p>I'm looking for something that makes this less of a pain:</p>
  
  <pre><code>&lt;?php
  $persons = array('John', 'Jack', 'Jill', 'Jason');
  ?&gt;
  
  &lt;?php $i = 0; ?&gt;
  &lt;?php if (isset($persons)): ?&gt;
  &lt;ul&gt;
  &lt;?php foreach ($persons as $name): ?&gt;
      &lt;li class="&lt;?= ($i++ % 2 === 0) ? 'odd' : 'even' ?&gt;"&gt;&lt;?= $name ?&gt;&lt;/li&gt;
  &lt;?php endforeach ?&gt;
  &lt;/ul&gt;
  &lt;?php endif ?&gt;
  </code></pre>
  
  <p>Does it really take the mess above to create something like this below?</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li class="odd"&gt;John&lt;/li&gt;
      &lt;li class="even"&gt;Jack&lt;/li&gt;
      &lt;li class="odd"&gt;Jill&lt;/li&gt;
      &lt;li class="even"&gt;Jason&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Is it only me that find the above near hideous? </p>
  
  <p>All those starting and closing of php-tags makes me cringe.</p>