I have solved the issue.
First of all, to answer @hcoat's comment, i want to have 3 custom options
(open_col
, close_col
, col_dims
) for form theming
. I passed them in the attr
option:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('field1', null, array('attr' => array('open_col' => true, 'col_dims' => '2-8')))
->add('field2', null, array('attr' => array('close_col' => true, 'col_dims' => '6-8')))
;
}
And retrieved those option values like this :
{% block form_row %}
{% spaceless %}
{% set open_col, close_col = 'open_col', 'close_col' %}
{% if open_col in attr|keys %}
<div class="mws-form-row">
<div class="mws-form-cols">
<div class="mws-form-col-{{ (open_col in attr|keys) ? attr['col_dims']:'4-8' }}">
{% elseif close_col in attr|keys %}
<div class="mws-form-col-{{ (open_col in attr|keys) ? attr['col_dims']:'4-8' }}">
{% else %}
<div class="mws-form-row">
{% endif %}
{{ form_label(form) }}
<div class="mws-form-item">
{{ form_widget(form) }}
</div>
{% if close_col in attr|keys %}
</div>
</div>
</div>
{% elseif open_col in attr|keys %}
</div>
{% else %}
</div>
{% endif %}
{% endspaceless %}
{% endblock form_row %}
It works fine !