Twig is scheduled for Drupal 8 as a theme
engine although it is not a complete replacement for the Drupal 7 theme engine.
Twig was developed by some people behind the Symfony framework and the two work together. Drupal 8 uses parts of Symfony and twig makes a good match. Twig can be used by itself and works in Drupal 7. I use Twig for a few things although not for themeing because twig only does a very small part of themeing.
Twig is sold as curing all sorts of diseases but it does not do much, it is just a refined version of Smarty, another blob of software that is oversold.
Twig is supposed to be secure but it is no more secure than the exisitng Drupal PHPtemplate engine. Twig happens to have some default settings to limit access to raw data but the very forst page of the simplest tutorial show you how to use the raw data, which means you have to build a security layer to clean data before it reaches Twig, exactly the same as the current Drupal theme engine.
Twig is supposed to replace a lot of things but you still need tokens, etc. The list goes on forever.
Twig is supposed to do away with programming, a claim made more forcibly for Smarty, and, like Smarty, Twig requires programming. Twig requires programming to produce the data used in Twig. If you use Twig for anything other than the most basic few lines of examples on the first page of a Twig tutorial, you are programming. Twig is designed to do what you used to do before you converted your web site to interactive handhelds and touch screens. Twig is a solution for Web sites before 2002 when HTC introduced the big selling smartphone, or perhaps 2000 when HTC invented the first smartphone, or 1999 when Japan released their clone of the 2012 Amazon Kindle Fire.
Yes, if you live outside of America, a lot of the
new inventions are old before they are
invented in America, one of the reasons Apple loses court cases outside of America. In the 1990s Microsoft invented the XMLHTTPRequest for Internet Explorer 5. The open source world calls it Ajax and the young things inventing the new
responsive Web call it
By the time we are using Drupal 9, the Web page will just be a set of regions with each region updated by something different to Twig. There might still be some large regions with legacy HTML that need Twig.There are a bunch of competitors with fancy names. Panels competes for layout control. If Panels wins the layout war and the JSON version of the Microsoft XMLHTTPRequest wins the content delivery wars, there will be nothing left for Twig in the middle.
Despite all the limitations of replacing the PHP scripting language with the Twig scripting language, and the overheads of Twig translating twig to PHP (Twig is a closet PHP code generator), Twig is what you will have to convert to in Drupal 8. You can start learning twig and converting in Drupal 7 using some of the Twig add-on modules (including mine :-)).
The Drupal 7 add-on module
Twig for Drupal attempts to add Twig to Drupal 7 for theme development. I have not yet found twif based theme that works with Twig for Drupal.
The Drupal 7 add-on module
Twig attempts to add Twig to Drupal 7 as an input filter. I do not know how you would use it. it looks like it might compete with tokens but tokens are already popular through Wiki markup and other uses. The Twig evangelists might suggest using the Twig features for disguising Twig scripting markup and disguise it as tokens to replace tokens.
Where can you use twig safely? email springs to mind. There is already an email editor with a scripting language added to let you create summary lists in emails. There are better long term approaches but some of the log term approaches may miss Drupal 8 core. Twig looks like it is locked and loaded for Drupal 8 core. You could safely replace the scripting languages in mail templates with Twig. The advantages of changing are slight. I wrote a very simple proof-of-concept module and the change was easy. this is one area where we can jump in and start using Twig.
Twig in D7
Here is a way to experiment with Twig in Drupal 7.
There is a Drupal 7 add on module named Twig, at drupal.org/project/twig, connecting Twig as a Drupal content input filter. This approach would be good to set up default templates for content but that does not happen with this module. Perhaps the module could connect to Cel to get a template.
Twig for Drupal, drupal.org/sandbox/ReneB/1075966, is a theme engine using Twig. Twig replaces only part of the current Drupal theme engine which means Twig for Drupal places Twig inside code performing the equivalent of the current phptemplate.php file.
I renamed the
Twig module to
Twig filter and put my Twig load code in as module
Twig. My modules using Twig, including
Mail twig, can use the one set of Twig functions and code without duplication. There was no response to my suggestion so I released my module as Twig7, drupal.org/sandbox/peter/1823890.
Twig is another markup scripting language emulating parts of PHP using PHP and has to be on your resume eventually. Beat the rush and learn Twig in Drupal 7 then you can start Drupal 8 development with several years of Twig experience.