[英]Twig, comparing variable to a string
I have a problem with a very simple template in twig when I need to compare a variable to a string. 当我需要将变量与字符串进行比较时,我在树枝中有一个非常简单的模板有问题。
The template 模板
{% if test_var != "" %}
Test 42
{% endif %}
The PHP code PHP代码
require_once REP_GLOBAL."/vendor/autoload.php";
$loader = new Twig_Loader_Filesystem(array(REP_GLOBAL."/ressources/twig/emails"));
$twig = new Twig_Environment($loader);
$template = $twig->loadTemplate('maj_coord_perso.html');
$msg = $template->render(array('test_var' => "TEST"));
echo $msg;
The error 错误
PHP Fatal error:
Uncaught exception 'Twig_Error_Syntax' with message 'Unexpected character "\\"
in "maj_coord_perso.html" at line 1' in ***/vendor/twig/twig/lib/Twig/Lexer.php:282\n
Stack trace:\n
#0 ***/vendor/twig/twig/lib/Twig/Lexer.php(203): Twig_Lexer->lexExpression()\n
#1 ***/vendor/twig/twig/lib/Twig/Lexer.php(109): Twig_Lexer->lexBlock()\n
#2 ***/vendor/twig/twig/lib/Twig/Environment.php(469): Twig_Lexer->tokenize('{% if address.w...', 'maj_coord_perso...')\n
#3 ***/vendor/twig/twig/lib/Twig/Environment.php(559): Twig_Environment->tokenize('{% if address.w...', 'maj_coord_perso...')\n
#4 ***/vendor/twig/twig/lib/Twig/Environment.php(331): Twig_Environment->compileSource('{% if address.w...', 'maj_coord_perso...')\n
The encoding of the template file is ISO-8859-1 but I'm having the same error with a UTF-8 encoded template. 模板文件的编码为ISO-8859-1,但使用UTF-8编码的模板时出现相同的错误。
What am I missing ? 我想念什么?
我找到了解决方案:
set_magic_quotes_runtime(0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.