简体   繁体   中英

Overriding forms template Symfony2, twig elements?

i'm trying to override a template for some forms.

This one being one of them

  public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('nombreBD','text', array( 'required' => true, 'label' => 'Nombre Base de Datos: '))
            ->add('Servidor','choice', array(
                            'choices'   => array('1' => 'Si', '0' => 'No'),
                            'required'  => true,
                            'multiple'  => false,
                            'expanded'  => true,
                            'label' => 'Servidor Existente?',

                  ))
            ->add('ServidorBD','entity',
                  array ('class' => 'MonseWebBundle:ServidoresBD',
                        'multiple' => true, 
                        'required' => true, 
                        'label' => 'Servidor de Base de Datos: ',
                         'query_builder' => function(EntityRepository $er) {
                         return $er->createQueryBuilder('u')
                         ->orderBy('u.url', 'ASC');
                                                                           },
                         ))
            ;
    }

And this being the template

{% block text_widget %}
<div class="round full-width-input" id="full-width-input">
    <input type="text" {{ block('attributes') }} value="{{ value }}" >
</div>
{% endblock %}

I think i succeded in the text inputs but i've got no idea how to set up the ones for the entity and the ones for the radio buttons (choice) because i don't know where the information is stored. For example, i don't quite know what block ('attributes') nor {{value}] return. Same as i don't know how to make of the radiobuttons selected.

I wanted to use this:

<label for="dropdown-actions">Dropdown</label>

                                    <select id="dropdown-actions">
                                        <option value="option1">Select your action here</option>
                                    </select>

for the entity "ServidoresBD" and this:

<label for="selected-radio" class="alt-label"><input type="radio" id="selected-radio" checked="checked" />A selected radio</label>
                                        <label for="unselected-radio" class="alt-label"><input type="radio" id="unselected-radio" />An uselected radio</label>

for the radio buttons.

Also, for a weird reason, all the labels in ALL the project appear as upper-case, no matter what style i put them. ALWAYS and this is really annoying.

Any help would be greatly appreciated.

The default form theming is stored under the Twig bridge. Here , you can find all blocks which are defined in the form theme.

Just take a look to this file & IMO, you will understand what you need to do. :)

Hope that helps.

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