php 7.4 写入变量中的 Twig 问题 [英] Twig problem with php 7.4 in write variable

查看:40
本文介绍了php 7.4 写入变量中的 Twig 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了 php7.3 并在这个项目中使用了 Twig

I using php7.3 on my project and use Twig in this project

将我的 php 版本升级到 7.4 后,我在树枝渲染中出现了一些错误.

After upgrade my php version to 7.4 i have some error in twig rendering.

我通过 Twig 变量设置了一些 html 类

I set some html class by Twig variable

例如:

<body class='{{global.direction}} preload {{bodyclass}}'></body>

当使用 php 7.3 时,Twig 渲染的输出是:

When using php 7.3 the output of Twig render is:

<body class='ltr preload main'></body>

而且我的来源没有问题.

And no problem in my source.

但是当我的 php 升级到 php 7.4 时,输出发生了变化!

But when my php upgraded to php 7.4 the output was changed!

<body class='ltr preloadmain'></body>

在变量之前的空间中删除了 Twig 并且我的源代码中发生了非常错误:/

Twig removed on space before variable and very error was happening in my source :/

从 Twig 到处调用变量,Twig 删除它之前的所有空间!

Everywhere call variable from Twig, The Twig remove all space before it!

有什么解决办法吗?

如何解决?

推荐答案

对我有用的一般答案(Opencart Twig 也是如此)与评论中提到的修复 Simo Heinonen 相关,即https://github.com/twigphp/Twig/pull/3004/commits/1fb0f9701d8443083495cd2645c

The general answer that worked for me (Opencart Twig too) is related to the fix Simo Heinonen mentioned in the comments i.e. https://github.com/twigphp/Twig/pull/3004/commits/1fb0f9701d8443083495cd2645e8a0c45d54c34d

不同版本的代码与上面显示的略有不同.对于 Opencart Twig(大多数版本,但使用 oc 3.0.3.3 进行了测试)显然已修复它:

Different versions will have somewhat different code than shown above. For Opencart Twig (most versions but tested with oc 3.0.3.3) what apparently fixed it was :

在文件 Lexer.php 中找到函数 lexData 第 163 行的变化:

Find in file Lexer.php function lexData line 163 change:

if (isset($this->positions[2][$this->position][0]) ) {
    $text = rtrim($text);
}

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

这篇关于php 7.4 写入变量中的 Twig 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆