How to render CSRF input in twig?

Ondrej Slinták picture Ondrej Slinták · Sep 19, 2011 · Viewed 34.7k times · Source

I know there's the usual way to render CSRF token hidden input with form_rest, but is there a way to render just CSRF input itself? I've overridden {% block field_widget %} in theme to render a piece of additional text. But as CSRF token is rendered in input field too and I got a piece of text I don't need next to a hidden field. So I'd like to render it separately with an argument that tells it not to render this text.

Answer

Henrik Bjørnskov picture Henrik Bjørnskov · Sep 20, 2011

you can do it with {{ form_widget(formView._token) }}