In my Symfony2 project, I noticed that there are only two layout options for rendering forms:
form_table_layout.html.twig
and
form_div_layout.html.twig
These both reside in symfony\src\Symfony\Bridge\Twig\Resources\views\Form, and I would like to add one of my own somewhere in my app\Resources directory.
The only issue I'm having, is when I add my new layout file (form_list_layout.html.twig) into app\Resources\views\Form, Symfony doesn't look for it and just looks in the default location instead (in the Twig directory).
I have tweaked my config.yml to tell it to include the new layout, but maybe I'm doing something wrong:
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
form:
resources: ['form_list_layout.html.twig']
EDIT: Okay, I've got Symfony2 looking in the right place now, but it doesn't seem to have any effect on the rendering of the form (I copied the contents of the table layout file into my new list layout file to test the theory, and my form is still rendering with <div> tags instead. This might be caused by the CraueFormFlowBundle I'm using, so I'll check it out).
The working config.yml:
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
form:
resources:
- ":Form:form_list_layout.html.twig"
EDIT 2: Doesn't look like its anything to do with the CraueFormFlowBundle, is there anything in my configuration that might be causing it to ignore the global form layout?
EDIT: Actually, it is working. As soon as I changed my layout file to include my list elements instead of the table layout content, it appeared okay.
You don't have to place it into an
appsubfolder; you can place it in any bundle you want. For example, in my case, I've placed it intoCommonBundle/Resources/views/Form/fields.html.twigand activate it in theconfig.ymlfile asOf course, if you put it into an
appsubfolder, you just omit the bundle name part: