php - method return html symfony2 -
i try send html code in symfony2 :
public function testaction() { $html = '<input type="text">' return $this->render('testbundle:default:index.htlm.twig',array( 'html' => $html, )); } when use html variable in page index.html.twig : {{ html }} result
<input type="text"> but not want result. result want page index.html.twig display me input (the text area).
an answer doc : http://twig.sensiolabs.org/doc/api.html#escaper-extension
the escaper extension adds automatic output escaping twig. defines tag, autoescape, , filter, raw.
when creating escaper extension, can switch on or off global output escaping strategy:
$escaper = new twig_extension_escaper('html'); $twig->addextension($escaper); if set html, variables in templates escaped (using html escaping strategy), except using raw filter:
{{ article.to_html|raw }} you can change escaping mode locally using autoescape tag (see autoescape doc syntax used before twig 1.8):
{% autoescape 'html' %} {{ var }} {{ var|raw }} {# var won't escaped #} {{ var|escape }} {# var won't double-escaped #} {% endautoescape %}
Comments
Post a Comment