我有这个用例。
范围内的默认文本,将在整个页面中使用。
使用 jQuery 将文本从“占位符”更改为“特定情况”
Ie,
在 html 中我想这样做:
(树枝/html 和 js)
{% block content %}
{% set location = '<span id="location">Somewhere</span>' %}
<p>Hey, hows the weather in {{ location | raw }}?</p>
<script>
var location = detectLocation();
update $(#location).html('location');
<script>
运行前脚本所需的输出:
嘿,某地的天气怎么样?
所需的输出后记运行(假设它输出澳大利亚):
嘿,澳大利亚的天气怎么样?
..但是由于树枝剥离空间我得到了什么:
嘿,某地的天气怎么样?
在我在仍在使用 twig 1.* 的遗留代码库上从 php7.0 迁移到 php7.4.3 后,就发生了这种情况。
如果您无法将 twig 更新到较新的版本,请使用以下修复方法。
edit twig/twig/lib/Twig/Lexer.php
,第 163 行更改:
if (isset($this->positions[2][$this->position][0]) ) {
$text = rtrim($text);
}
to
if (isset($this->positions[2][$this->position][0]) && ($this->options['whitespace_trim'] === $this->positions[2][$this->position][0])) {
$text = rtrim($text);
}
更好的解决办法:更新你的 twig 版本。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)