2011-09-17 8 views
8

मैं symfony2 का उपयोग कर रहा हूं। मैं twig में डिफ़ॉल्ट div शैली फार्म ब्लॉक को ओवरराइड करने की कोशिश कर रहा हूँ।एक सिम्फनी 2 फॉर्म थीम बनाना - फ़ील्डसेट और सूची शैली

सबसे पहले, क्या फ़ील्डसेट और सूची (उल -> ली) दृष्टिकोण के उपलब्ध कार्यान्वयन के बारे में कोई जानकारी है या पता है?

उत्तर

0

http://symfony.com/doc/2.0/cookbook/form/form_customization.html

मैं thoose के कार्यान्वयन के बारे में पता नहीं कर रहा हूँ, लेकिन आप उन्हें बनाने के लिए और एक पुल का अनुरोध खोलने के लिए स्वागत है।

1

डिफॉल्ट रूप से, टवीग फ़ॉर्म को रेंडर करते समय एक div लेआउट का उपयोग करता है। हालांकि, आप टेबल लेआउट में फॉर्म प्रस्तुत कर सकते हैं। इस तरह के एक लेआउट का उपयोग करने form_table_layout.html.twig संसाधन का उपयोग करें:

प्रकार में

: क्षण के लिए

# app/config/config.yml 

twig: 
    form: 
     resources: ['form_table_layout.html.twig'] 
3

, मैं इस तरह fieldset समर्थन कार्यान्वित

public function buildView(FormView $view, FormInterface $form, array $options) 
{ 
    $view->setAttribute('fieldsets', 
      array(
       array(
        'legend' => 'film.group.date', 
        'content'=> array(
         'theaters_release_date', 
         'storage_media_release', 
         'storage_media_release_date', 
         'vod_release_date' 
         )), 
       array(
        'legend' => 'film.group.country', 
        'content'=> array('countries')), 
        )); 
} 

मैं एक है टेम्पलेट का नाम फ़ील्डसेट.html.twig है, जो दृश्य के गुणों का उपयोग करता है:

{% macro fieldset_block(fieldset, form) %} 
<fieldset{% if fieldset.subform is defined %} class="{{ fieldset.subform }}"{% endif %}> 
    <legend>{{fieldset.legend | trans }}</legend> 
    {% if fieldset.content is defined%} 
     {% for row in fieldset.content %} 
      {{ form_row(form[row]) }} 
     {% endfor %} 
    {% endif %} 
    {% if fieldset.subform is defined %} 
     {# Couldn't get some recursivity (simply call form widget) here... too bad #} 
     {% if form[fieldset.subform].get('attr').fieldsets is defined %} 
      {% for subfieldset in form[fieldset.subform].get('attr').fieldsets %} 
       {{ _self.fieldset_block(subfieldset, form[fieldset.subform]) }} 
      {% endfor %} 
     {% else %} 
      {% for row in form[fieldset.subform] %} 
       {{ form_row(row) }} 
      {% endfor %} 
     {% endif %} 
    {% endif %} 
    {% if fieldset.items is defined%} 
     {% for fieldset in fieldset.items %} 
      {{ _self.fieldset_block(fieldset, form) }} 
     {% endfor %} 
    {% endif %} 
</fieldset> 
{% endmacro %} 

{% block form_widget %} 
    {% for fieldset in form.get('attr').fieldsets %} 
     {{ _self.fieldset_block(fieldset, form) }} 
    {% endfor %} 
{% endblock %} 
2

यहां एक सिम्प है https://gist.github.com/spcmky/8512371

एक सूची के साथ divs बदलने के लिए, form_widget_compound और form_rows को देखो: le उदाहरण fieldset। आप कर सकते हैं:

{% block fieldset_widget %} 
    {% spaceless %} 
     <fieldset {{ block('widget_container_attributes') }}> 
      {% if title is defined %}<legend>{{ title }}</legend>{% endif %} 
       <ul> 
       {% for child in form %} 
        <li> 
         {{ form_widget(child) }} 
        </li> 
       {% endfor %} 
       </ul> 
     </fieldset> 
    {% endspaceless %} 
{% endblock %} 
संबंधित मुद्दे