Twig removes spaces before variables in php 7.4

If it is not possible to update the version of the Twig library, but the server only has PHP 7.4 and higher, then there is a quick fix for the problem with the disappearance of spaces before variables.

Available:

<span>Brand name {{global.brand}}</span>

Output without space

<span>Brand nameAriston</span>

Solution:

/twig/twig/lib/Twig/Lexer.php

$text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor);
if (isset($this->positions[2][$this->position][0])) {
    $text = rtrim($text);
}

replace with

$text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor);
if (isset($this->positions[2][$this->position][0]) && ($this->options['whitespace_trim'] === $this->positions[2][$this->position][0])) {
    $text = rtrim($text);
}

Source1, Source2

737 0

Comments

Be the first to review this item. Share your rating and review so that other customers can decide if this is the right item for them.
You have to log in to leave a comment. Sign in

Similar articles

Create and download CSV in PHP

Consider the possibility of quickly creating a CSV file with automatic file download. Consider the formation, separators and header for the ability to download the file.

Long-term storage of the basket in the online store

Consider options for popular options for storing goods in a shopping cart in an online store. Let's outline the pros and cons of such storage. Consider options for long-term storage of the basket.