Migration from Twig to Latte
Are you migrating a project written in Twig to the more modern Latte? We have a tool to make the migration easier. Try it out online.
You can download the tool from GitHub or install it using Composer:
The converter doesn't use simple regular expression substitutions, instead it uses the Twig parser directly, so it can handle any complex syntax.
A script twig-to-latte.php
is used to convert from Twig to Latte:
Conversion
The conversion requires manual editing of the result, since the conversion cannot be done unambiguously. Twig uses dot syntax,
where {{ a.b }}
can mean $a->b
, $a['b']
or $a->getB()
, which cannot be
distinguished during compilation. The converter therefore converts everything to $a->b
.
Some functions, filters or tags have no equivalent in Latte, or may behave slightly differently.
Example
The input file might look like this:
After converting to Latte, we get this template: