简体   繁体   中英

twig template engine's form_widget

I am currently updating a PHP application so that it uses the very nice twig template engine .

I have hit a snag as to how to approach this issue. The application has their own set of custom developed form classes. Essentially, one can progammatically add fields, set methods and actions to the form object. Once this is all done, a the render() method is called, which then spits out a generated HTML snippet for the form.

I was able to output the form in a template using the raw filter like so:

{{ form|raw }}

While this works well, I notice that symfony2 has a method called form_widget() which specifically deals with rendering forms without having to output as raw.

I would like to adapt the application so that I can use form_widget() , however, I am unable to find any indepth documentation on it. Can anyone point out how data should be passed to form_widget() without using the symphony2 framework? Whether it is an array, object, or something else?

After looking at the trawling through Symphony's source code, it looks like all they have done is created an extension so that forms will be rendered as HTML:

'form_widget' => new \Twig_Function_Method($this, 'renderWidget', array('is_safe' => array('html'))),

So, I guess all I need to do is create my own twig extension to provide similiar functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM