Reputation: 17
I want to render twig template manually, the code is like:
$template = $this->twig->loadTemplate('MyBundle::board.html.twig'); $result = $template->render(array('entities'=>$query->getResult()));
return $result;
When I echo $result
, everything works well, Chrome renders all HTML code correctly, but I need to return $result
from a function, then render in twig as {{result}}
, but I can not use {{result|raw}}
.
Any other way to make twig don't escape html?
Upvotes: 0
Views: 1513
Reputation: 225
Not sure why can't you use {{ result|raw }}. But escaping can be disabled for the whole environment. Here is something I have used for rendering some html from string, with escaping turned off.
$twig = new \Twig_Environment( new \Twig_Loader_String(),
array(
'autoescape' => false
)
);
$body = $env->render(
$templateString,
$parameters
);
Though probably this is not what you are looking for.
Upvotes: 1