2016-05-16 7 views
-2

をカスタマイズフォーム小枝は、私は、この通常の方法でフォームのウィジェットを拡張 ..私は自分のフォームのスタイルのカスタマイズに問題があるスタイル

<div id="requests_tipi" class="form-control scroll-select"> 
    <input type="checkbox" id="requests_tipi_1" name="requests[tipi][]" value="1" checked="checked"> 
    <label for="requests_tipi_1">Appartamento</label> 
    <input type="checkbox" id="requests_tipi_2" name="requests[tipi][]" value="2" checked="checked"> 
    <label for="requests_tipi_2">Casa Colonica</label> 
    <input type="checkbox" id="requests_tipi_3" name="requests[tipi][]" value="3" checked="checked"> 
    <label for="requests_tipi_3">Garage</label> 
    <input type="checkbox" id="requests_tipi_4" name="requests[tipi][]" value="4"> 
    <label for="requests_tipi_4">Loft</label> 
</div> 

Iだろう。このようなリスト:

<ul> 
    <li><label for="requests_tipi_1">Appartamento</label><input type="checkbox" id="requests_tipi_1" name="requests[tipi][]" value="1" checked="checked"></li> 
... 
</ul> 

どのように私は私のsymfonyのフォームをカスタマイズするために行うことができます???

おかげ

答えて

1

これは、あなたが(あなたのケースでtipi)個々のフィールドのレンダリングをカスタマイズする方法である:

http://symfony.com/doc/current/cookbook/form/form_customization.html#how-to-customize-an-individual-field

をし、これが元の書式が定義されているところである(そして、あなたが「取ることができる場所インスピレーション」:):

https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig#L45

だから、のようなものこれは動作します(私はテストしていないことに注意してください。調整する必要があるかもしれません)。テンプレートファイルの一番上に次のコードを入れてください:

{% form_theme form _self %} 

{% block _requests_tipi_widget %} 
    <ul {{ block('widget_container_attributes') }}> 
    {% for child in form %} 
     <li> 
     {{ form_label(child, null, {translation_domain: choice_translation_domain}) }} 
     {{ form_widget(child) }} 
     </li> 
    {% endfor %} 
    </ul> 
{% endblock _requests_tipi_widget %} 
関連する問題