months Template cache hot reload Operator precedence fixes Arrows everywhere Named arguments (macros, ...) Twig callable arguments as snake-case or camelCase Colon as argument separator Yielding instead of echo-ing Inline comments ChainCache Argument unpacking Static Analyzer support{% types %} Compile time checks {% guard %} Functions: enum, html_cva, enum_cases Filters: find, singular, plural, shuffle Tests: sequence, mapping Tons of internal changes/refactoring to make the code more robust (no more global functions!)
'auto_reload' => false, 'cache' => __DIR__.'/cache', ]); // prime the cache echo $twig->load('index.twig')->render([]); // update the template file_put_contents(__DIR__.'/index.twig', file_get_contents(__DIR__.'/index.twig').'foo'); // still use the cached version echo $twig->load('index.twig')->render([]); // remove the cache for this template $twig->removeCache('index.twig'); // refresh the cache with the updated template echo $twig->load('index.twig')->render([]);
explicit parentheses around the "??" binary operator to avoid behavior change in the next major version as its precedence will change in "index.twig" at line 4.
World"|upper # this is an inline comment }} {{ { # this is an inline comment fruit: 'apple', # this is an inline comment color: 'red', # this is an inline comment }|join(', ') }} {{ "Hello World"|upper # this is an inline comment }} {{ "Hello World"|upper # this is an inline comment }} Nope Yep Yep Yep
Twig Function is a Twig callable A Twig Test is a Twig callable A Twig Tag is NOT a Twig callable 'needs_environment' => false, 'needs_context' => false, 'needs_charset' => false, 'is_variadic' => false, 'deprecation_info' => null, 'deprecated' => false, 'deprecating_package' => '', 'alternative' => null,
in values %} {% if not loop.first and value > loop.previous %} The value just increased! {% endif %} {{ value }} {% if not loop.last and loop.next > value %} The value will increase even more! {% endif %} {% endfor %} https://github.com/twigphp/Twig/pull/4135 New
stopOnFabien = false %} {% for user in users if not stopOnFabien %} - {{ user }} {% set stopOnFabien = user == 'Fabien' %} {% endfor %} https://github.com/twigphp/Twig/pull/4251 {% for user in users if loop.length != 5 %} - {{ user }} {% endfor %}