Symfony 如何在不转义的情况下手动呈现细枝模板?
我想手动渲染细枝模板,代码如下:Symfony 如何在不转义的情况下手动呈现细枝模板?,symfony,twig,Symfony,Twig,我想手动渲染细枝模板,代码如下: $template = $this->twig->loadTemplate('MyBundle::board.html.twig'); $result = $template->render(array('entities'=>$query->getResult())); return $result; 当我echo$result时,一切正常,C
$template = $this->twig->loadTemplate('MyBundle::board.html.twig'); $result = $template->render(array('entities'=>$query->getResult()));
return $result;
当我echo$result
时,一切正常,Chrome正确地呈现所有HTML代码,但我需要从函数返回$result
,然后在twig中呈现为{{result}}
,但我不能使用{result}raw}
有没有其他方法可以让小树枝不逃逸html 我认为转义应该在
MyBundle::board.html.twig
不确定为什么不能使用{{result}raw}。但是,可以在整个环境中禁用转义。下面是我在关闭转义的情况下从字符串中呈现一些html时使用的东西
$twig = new \Twig_Environment( new \Twig_Loader_String(),
array(
'autoescape' => false
)
);
$body = $env->render(
$templateString,
$parameters
);
虽然这可能不是你想要的