Drupal 8 Twig vs PHP template and twig basics

Drupal 8 uses Twig framework instead of PHPTemplate. This means that now, instead of the usual *.tpl.php files we use the *.html.twig files.

Twig is a PHP-based compiled templating language. When your web page renders, the Twig engine takes the template and converts it into a 'compiled' PHP template which it stores in a protected directory in sites/default/files/php/twig. The compilation is done once. Template files are cached for reuse and are recompiled on clearing the Twig cache.

I would also recommend to watch this session on Twig from DrupalCon Portland.

 

Another video which gives good intro of Twig