2013-12-09 89 views
0

当我需要将变量与字符串进行比较时,我遇到了一个枝条中非常简单的模板问题。Twig,将变量与字符串进行比较

模板

{% if test_var != "" %} 
    Test 42 
{% endif %} 

的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; 

错误

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 

模板文件的编码是ISO-8859-1,但我具有与UTF-8编码模板相同的错误。

我错过了什么?

回答

0

我已经找到了解决办法:

set_magic_quotes_runtime(0); 
相关问题