Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 细枝模板未完成标记_Variables_Tags_Twig - Fatal编程技术网

Variables 细枝模板未完成标记

Variables 细枝模板未完成标记,variables,tags,twig,Variables,Tags,Twig,我将使用细枝作为公共服务的邮件模板引擎。 我的问题是,如果用户未完成细枝变量标记-这将导致异常,并将制动系统 Hello, {{ name *(instead {{ name }})* message body 有没有办法忽略细枝语法中的错误?作为一个选项,您可以使用registerUndefinedFunctionCallback或registerUndefinedFilterCallback抑制细枝错误语法 您可以尝试以下方法: $twig->registerUndefined

我将使用细枝作为公共服务的邮件模板引擎。 我的问题是,如果用户未完成细枝变量标记-这将导致异常,并将制动系统

Hello, {{ name  *(instead {{ name }})*

message body 

有没有办法忽略细枝语法中的错误?

作为一个选项,您可以使用registerUndefinedFunctionCallback或registerUndefinedFilterCallback抑制细枝错误语法

您可以尝试以下方法:

$twig->registerUndefinedFunctionCallback(function ($name) { 

   if (function_exists($name)) {
    return new Twig_Function_Function($name);
   }

   return false; 
});
它应该返回false

或者,在twig尝试解析时,简单地捕获异常:

try {

   $twig->parse($twig->tokenize($template));


} catch (Twig_Error_Syntax $e) {

    // here you are    

}