2012-03-10 53 views
0

在我的表單模板的表單控件的:定製中的Symfony2 /枝條

{% block field_label %} 
{% spaceless %} 
    <label {{ block('widget_attributes') }}></label> 
{% endspaceless %} 
{% endblock %} 

我需要添加一些額外的屬性class,當然,顯示的標籤(可能轉換)。我發現{{ block('widget_attributes') }}存儲了實際標籤屬性的string

有機會獲得array類型以輕鬆修改它嗎?在哪裏可以找到所有block名稱來自定義外觀以適合我的需求?感謝您的幫助。

回答

1

沒關係記事本++幫我找到這個文件:定義

vendor\symfony\src\Symfony\Bridge\Twig\Resources\views 

三種類型的標籤:

{# Labels #} 

{% block generic_label %} 
{% spaceless %} 
    {% if required %} 
     {% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %} 
    {% endif %} 
    <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label> 
{% endspaceless %} 
{% endblock %} 

{% block field_label %} 
{% spaceless %} 
    {% set attr = attr|merge({'for': id}) %} 
    {{ block('generic_label') }} 
{% endspaceless %} 
{% endblock field_label %} 

{% block form_label %} 
{% spaceless %} 
    {{ block('generic_label') }} 
{% endspaceless %} 
{% endblock form_label %}