a Sensio Labs Product

The flexible, fast, and secure
template language for PHP

Twig 0.9.3 released

I have just released Twig 0.9.3.

This release dramatically improves the performance of loops. It’s also the first backward incompatible release since the beginning of the project.

Loops are also much more easier to use as the items filters is not needed anymore:

{# before 0.9.3 #}
{% for k, v in values|items %}

{# as of 0.9.3 #}
{% for k, v in values %}

The previous template still work as items is now a noop filter. So, you can safely removed it

The loaders do not take the cache and autoReload arguments anymore. Instead, the Twig_Environment class has two new options: cache and auto_reload. Upgrading your code means changing this kind of code:

$loader = new Twig_Loader_Filesystem('/path/to/templates', '/path/to/compilation_cache', true);
$twig = new Twig_Environment($loader);

to something like this:

$loader = new Twig_Loader_Filesystem('/path/to/templates');
$twig = new Twig_Environment($loader, array(
  'cache' => '/path/to/compilation_cache',
  'auto_reload' => true,
));

The complete changelog follows:

  • made cache and auto_reload options of Twig_Environment instead of arguments of Twig_Loader
  • deprecated the “items” filter as it is not needed anymore
  • optimized template loading speed
  • removed output when an error occurs in a template and render() is used
  • made major speed improvements for loops (up to 300% on even the smallest loops)
  • added properties as part of the sandbox mode
  • added public properties support (obj.item can now be the item property on the obj object)
  • extended set tag to support expression as value ({% set foo as ‘foo’ ~ ‘bar’ %} )
  • fixed bug when \ was used in HTML
This website is powered by PHP and Twig.