سؤال

I'm using Symfony 2.4. What I am trying to do is to set form attributes on the form level which are accessible to each individual widget.

I have a custom form theme which can render the form slightly differently if it is a horizontal or vertical layout. I'd like to be able to specify { 'horizontal': true } as an attribute on the form, then be able to read it while I'm reading each widget.

Is it possible? I want to avoid needing to do this on every widget.

{{ form_row(form.person.province, {horizontal:true}) }}
{{ form_row(form.person.postalCode, {horizontal:true}) }}
{{ form_row(form.person.phone, {horizontal:true}) }} 
هل كانت مفيدة؟

المحلول

couldn't you achieve that in your own form theme?

{% block form_row %}
  {% spaceless %}
  {% if horizontal|default(true) %} {# or something along these lines #}
    ...
  {% else %}
    ...
  {% endif %}
  {% endspaceless %}
{% endblock form_row %}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top