Menu Close

How to fix TWIG whitespace bug in Php 7.4 and Opencart 3.0.x

If you recently upgraded to php 7.4 and are using Opencart 3.0.x.x, you may encounter some bugs. In the following description I will show you how to repair them. If you login to the admin page  and Display errors option is Enabled, then on your screen you will see more messages with this error:

Notice: Trying to access array offset on value of type null in /storage/vendor/scss.inc.php on line 1753

To fix this error/warning you need to go to your storage/vendor and edit scss.inc.php and change this code:

$key = $key[1];

in to:

$key = isset($key[1]) ? $key[1] : null;

Or to set Display errors to Off.

Another issue is whitespace from TWIG library doesn’t work on php 7.4 as you can see in the screenshot below where icons should be displayed.

To fix this design bug you need to navigate to system/library/template/twig/ and edit the file Lexer.php. Here you need to change this code(lines 163-165 ):

$text = rtrim($text);

with this code

            if ($this->options['whitespace_trim'] === $this->positions[2][$this->position][0]) {
                // whitespace_trim detected ({%-, {{- or {#-)
                $text = rtrim($text);
            }

After that whitespace will work again and icons will be shown.

5 Comments

  1. Avatar
    Timo

    Thanks for sharing you hack! I can’t upgrade to the current Twig version (which also fixes this) without major effort, so your solution helped me a lot as a quick fix! 🙂

  2. Avatar
    mesteradam

    Refreshing the theme cache (gear icon on the top-right corner of the admin home screen) may be necessary after the changes.

  3. Avatar
    Ulan

    Perfect! After many hours of digging I found root cause. And after searching a lot finally found your solution for whitespacing. Solved perfectly!
    THANKS!

  4. Avatar
    kokkez

    Thank you for sharing. Hours of search, as for ULAN, but finally found your solution.
    Thank you very much for your time.

  5. Avatar
    Leo Venticola

    Hola, solucione mi problema. Gracias, me salvaste de escribir mucho codigo. 🙂

    En Slim Framework la linea que hay que cambiar es la 150 en el archivo vendor/twig/twig/lib/Twig/lexer

Leave a Reply

Your email address will not be published. Required fields are marked *