Drupal 8 | Twig template engine

Twig is a modern template engine for PHP using in Drupal 8. Twig is Fast, Secure and Flexible, it is part of the Symfony2 framework.

One of the Drupal 8 change is that all of the theme_* functions and PHPTemplate based *.tpl.php files have been replaced in by *.html.twig template files.

Drupal 8 Twig replaces PHPTemplate as the default Drupal templating engine.

PHP Template

<?php if ($items): ?>
  <?php foreach ($items as $item): ?>
    * <?php echo $item ?>
  <?php endforeach; ?>
<?php else: ?>
    No item has been found.
<?php endif; ?>

Twig Template

{% for item in items %}
  * {{ item }}
{% else %}
  No item has been found.
{% endfor %}
shanidkv's picture