Commerce 1.3: upgrading to Twig 3 and PHP 7.4
As we've taken the opportunity in Commerce 1.3 to increase the minimum PHP version, modernising dependencies we use has been one of the focus points throughout this release cycle. While not as flashy as new features like built-in multilingual support, this type of maintenance is important for stability and future compatibility.
We recently announced PHP 7.4 will be the minimum on all our extras starting January 1st. As we don't expect Commerce 1.3 to hit stable until January, we're taking a head start by requiring 7.4 now in the developer builds.
We've now brought the Twig template engine up to date to v3.4 (from v1.43) in the latest developer build, 1.3.0-dev5. That release is now available for testing in the pre-releases channel.
This Twig upgrade does come with a couple of breaking changes. Most of them are internal, and will not affect your webshops.
One exception is the {% spaceless %}
tag. That has been removed, but was used in various Commerce templates. Most likely, it's in your custom themes as well.
As a result all usages of {% spaceless %}...{% endspaceless %}
need to be replaced with {% apply spaceless %}...{% endapply %}
.
To help with this change Commerce 1.3 will scan your template folders on upgrade and attempt to fix the syntax automatically. A backup will be placed alongside updated files, with a .comm13.bk
extension, and the installation log will tell you exactly which files were changed.
However, the automatic upgrade may not catch everything, and also does not check extension templates that are loaded dynamically. We recommend doing a quick find & replace across any custom themes and extensions to identify any usages of "spaceless" to update proactively, so you don't run into issues with the upgrade.
As the apply syntax also exists in v1, you can use {% apply spaceless %}
now, before the upgrade to v1.3. This works all the way back to v1.0.1. Updates for our Red and Blue starter packs are also available now.
If you have any advanced Twig implementations (custom twig extensions, or making calls to $commerce->twig
rather than $commerce->view()
), additional steps may be needed to be compatible with Commerce 1.3, depending on what was previously implemented. If you have such a use case and aren't sure how to prepare that for 1.3, drop us an email. We're happy to help!