Why Latte as a Templating Engine

When it comes to using templating engines in PHP, we have various solutions. Blade, Twig, Latte, Plates, Volt, to name a few.

We opted to use Latte because it’s fast, reliable, and very easy to integrate with WordPress. Also, the company that built Latte, Nette, also has a great PHP debugger called Tracy, which really goes well with Latte, and helps tremendously with PHP and WordPress debugging.

It’s light, syntax is really clean and easy to learn with the help of a very well written documentation.


PHP / Latte comparison for the same block of code


<?php if (!empty($items)): ?>
  <?php $counter = 1; ?>
  <?php foreach ($items as $item): ?>
    <li id="item-<?php echo $counter++; ?>">
        echo htmlSpecialChars(mb_convert_case($item, MB_CASE_TITLE)); 
  <?php endforeach; ?>
<?php endif; ?>


<ul n:if="!empty($items)">
  <li n:foreach="$items as $item" id="item-{$iterator->counter}">{$item|capitalize}</li>

Here’s an example of a really useful helper that doesn’t print if the content is undefined or falsy.


<?php if (!empty($title)): ?>
  <h2><?php echo $title; ?></h2>
<?php endif; ?>


<h2 n:ifcontent>{$title}</h2>
Join Our Newsletter

To get updates about Theme Redone