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.

theme-redone-wordpress-starter-latte-intro-text

PHP / Latte comparison for the same block of code

PHP

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

Latte

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

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

PHP

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

Latte

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

To get updates about Theme Redone