You have multiple ways to install Twig.
curl -s http://getcomposer.org/installer | php
{
"require": {
"twig/twig": "1.*"
}
}
php composer.phar install
Note
If you want to learn more about Composer, the composer.json file syntax and its usage, you can read the online documentation.
Note
Using PEAR for installing Twig is deprecated and Twig 1.15.1 was the last version published on the PEAR channel; use Composer instead.
New in version 1.4: The C extension was added in Twig 1.4.
Note
The C extension is optional but as it brings some nice performance improvements, you might want to install it in your production environment.
Twig comes with a C extension that enhances the performance of the Twig runtime engine; install it like any other PHP extensions:
$ cd ext/twig
$ phpize
$ ./configure
$ make
$ make install
Note
You can also install the C extension via PEAR (note that this method is deprecated and newer versions of Twig are not available on the PEAR channel):
For Windows:
Tip
For Windows ZendServer, ZTS is not enabled as mentioned in Zend Server FAQ.
You have to use configure --disable-all --disable-zts --enable-cli --enable-twig=shared to be able to build the twig C extension for ZendServer.
The built DLL will be available in C:\\php-sdk\\phpdev\\vcXX\\x86\\php-source-directory\\Release
Finally, enable the extension in your php.ini configuration file:
extension=twig.so #For Unix systems
extension=php_twig.dll #For Windows systems
And from now on, Twig will automatically compile your templates to take advantage of the C extension. Note that this extension does not replace the PHP code but only provides an optimized version of the Twig_Template::getAttribute() method.