Blog

BranchCMS Upgrades

Eric Tompkins
Aug 23, 2021

Twig 3 Supported

BranchCMS is now fully supporting Twig version 3. The previous version that was supported was Twig Version 1. We recommend that all websites update to use Twig 3 as soon as possible.

Upgrading BranchCMS to Twig 3 lets us take advantage of better templating performance and best practices. It's also where we'll be doing all of our future updates. Twig version 1 will technically still be supported by BranchCMS, but it will no longer be updated, improved or added to.

For the web developer there isn't a lot of changes that you'd need to make to your current code.

The biggest change is that the {% spaceless  %} tag has been removed. It should be changed to use the apply tag with the spaceless filter. 

For example, convert

{% spaceless %}
    <p>Some HTML here</p>
{% endspaceless %}

to

{% apply spaceless %}
    <p>Some HTML here</p>
{% endapply %}

The other difference is how macros are supported and it's mostly around using macros that were defined in the same template. To quote the Twig documentation:

When macro usages and definitions are in the same template, you don't need to import the macros as they are automatically available under the special _self variable:

<p>{{ _self.input('password', '', 'password') }}</p>

{% macro input(name, value, type = "text", size = 20) %}
    <input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}"/>
{% endmacro %}

Updating your website to use Twig version 3

To update your website to use Twig version 3 first search your code for {% spaceless %} and change it to use {% apply spaceless %} as described above.

Then, in the administration click on "Settings" in the top bar and go to "General Settings".

As long as the "Template engine" field is set to Twig, then you'll see a "Twig version" field. Set it to "3" and then save. 

Test your site. If you notice any issues change back to version 1, fix the issues, and then switch back.

90% of websites should be able to switch to Twig version 3 with no issues. 

If you have any questions at all please contact our support team.

Sign up for our newsletter to receive invaluable information about BranchCMS, web design & development.