我試圖自定義Symfony2表單渲染,以便爲生成的每個選擇添加一個類。 我認爲有一個自定義form_div_layout.html.twig:Symfony2:爲每個選擇添加類
{% block choice_widget_collapsed %}
{% spaceless %}
<select class='myclass' {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
{% if empty_value is not none %}
<option value="">{{ empty_value|trans({}, translation_domain) }}</option>
{% endif %}
{% if preferred_choices|length > 0 %}
{% set options = preferred_choices %}
{{ block('choice_widget_options') }}
{% if choices|length > 0 and separator is not none %}
<option disabled="disabled">{{ separator }}</option>
{% endif %}
{% endif %}
{% set options = choices %}
{{ block('choice_widget_options') }}
</select>
{% endspaceless %}
{% endblock choice_widget_collapsed %}
,並使用它與
{% form_theme form 'YOPYourOwnPoetBundle:Form:form_div_layout.html.twig' %}
會做的伎倆。
但是,'myclass'類不會添加到select中。 我在做什麼錯?
你是否偶然通過了其他課程?如果你也在這裏粘貼生成的html,這將有所幫助。 – gilden 2012-07-06 06:21:31