a Sensio Labs Product

The flexible, fast, and secure
template engine for PHP

Questions & Feedback

License

Creative Commons License Twig documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

Installation

You have multiple ways to install Twig.

Installing the Twig PHP package

Installing from the tarball release

  1. Download the most recent tarball from the download page
  2. Unpack the tarball
  3. Move the files somewhere in your project

Installing the development version

  1. Install Git
  2. git clone git://github.com/fabpot/Twig.git

Installing the PEAR package

  1. Install PEAR
  2. pear channel-discover pear.twig-project.org
  3. pear install twig/Twig (or pear install twig/Twig-beta)

Installing the C extension

New in version 1.4: The C extension was added in Twig 1.4.

Twig comes with a C extension that enhances the performance of the Twig runtime engine.

You can install it via PEAR:

  1. Install PEAR
  2. pear channel-discover pear.twig-project.org
  3. pear install twig/CTwig (or pear install twig/CTwig-beta)

Or manually like any other PHP extension:

1
2
3
4
5
$ cd ext/twig
$ phpize
$ ./configure
$ make
$ make install

For Windows:

  1. Setup the build environment following the PHP documentation
  2. Put Twig's C extension source code into C:\php-sdk\phpdev\vcXX\x86\php-source-directory\ext\twig
  3. Use the configure --disable-all --enable-cli --enable-twig=shared command instead of step 14
  4. nmake
  5. Copy the C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release_TS\php_twig.dll file to your PHP setup.

Tip

For Windows ZendServer, TS is not enabled as mentionned 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:

1
2
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.

This website is powered by PHP and Twig. The Twig logo is © 2010-2012 Sensio Labs