Closed frankdavid closed 12 years ago
A form theme does not need to extend another form theme at all. It is even better to avoid extending as it would forbid using several themes (as the first one would define all blocks and so blocking next ones)
Yes, however, the template "SonataAdminBundle:Form:form_admin_fields.html.twig" does extend another form theme(SonataAdminBundle:Form:silex_form_div_layout.html.twig). What I'm saying is it would better to remove that and change it to use - in case it does not affect other parts of the framework. I'm not involved in development, a developer should tell if the change is possible and makes sense.
@stof Right now is there any way to achieve extending and changing blocks from "silex_form_div_layout.html.twig"? I want to make 'date' to have this defaults options without touching any other bundle but mine, and without having to place 'single_text' everywhere in my bundle:
->add('startDate', 'date', array(
'widget' => 'single_text',
'format' => 'YYYY-MM-dd',
'attr' => array('class' => 'datepicker'),
))
Im thinking in overriding this block from 'silex_form_div_layout.html.twig' :
{% block date_widget %}
{% spaceless %}
{% if widget == 'single_text' %}
{{ block('field_widget') }}
@stof What's the use case for using several themes for the same form? IMO that's a pretty bad practice, because blocks can and will conflict anyway.
@bschussek As I said in an issue on the Twig repo, a use case is for shared bundles to provide the needed rendering for their custom types, without having to know all other form bundles you are using to change the parent template of their theme
If I want to override some blocks in my own form theme from form_admin_fields.html.twig by using the 'use' statement, I get the following error: Template "SonataAdminBundle:Form:form_admin_fields.html.twig" cannot be used as a trait. In Symfony2 a view cannot be used as a trait if it extends another view. It would be nice if I could redefine some blocks of the default admin template, a solution could be to change
{% extends 'SonataAdminBundle:Form:silex_form_div_layout.html.twig' %}
to{% use 'SonataAdminBundle:Form:silex_form_div_layout.html.twig' %}
(I'm not 100% sure, this will work the same as now but resolves this problem)A very similar issue with symfony2 core engine: https://github.com/symfony/symfony/issues/1182