How to customize the data-prototype attribute in Symfony 2 forms

后端 未结 11 1147
梦如初夏
梦如初夏 2020-12-12 11:35

Since umpteens days, I block on a problem with Symfony 2 and forms.

I got a form of websites entities. \"Websites\" is a collection of website\'s entities and each w

11条回答
  •  离开以前
    2020-12-12 12:28

    To customize differently existing collection items VS prototype, you can override collection_widget like this:

    {%- block collection_widget -%}
        {% if prototype is defined %}
            {%- set attr = attr|merge({'data-prototype': form_row(prototype, {'inPrototype': true} ) }) -%}
        {% endif %}
        {{- block('form_widget') -}}
    {%- endblock collection_widget -%}
    

    And then in your custom entry:

    {% block _myCollection_entry_row %}
    
      {% if(inPrototype is defined) %}
          {# Something special only for prototype here #}
      {% endif %}
    {% endblock %}
    

提交回复
热议问题