Symfony 形式 div css class
Symfony Form div css class
使用 Symfony 3 并像这样构建一个表单域:
$builder
->add('tittle')
->add('price');
结果类似于:
<div>
<label ...></label>
<input ...>
</div>
我希望结果在包装 div
中包含自定义 css classes,例如:
<div class='wrap-title'>
<label ...></label>
<input ...>
</div>
<div class='wrap-price'>
<label ...></label>
<input ...>
</div>
尝试按照描述的方式做 here 并没有提供一种方法来将 class 添加到包装 div
中,只是其中的东西。
我不想使用 bootstrap 主题。我真的需要在那里添加一些我自己的东西作为 class。这可能吗?
希望这个回答能对您有所帮助:
我认为不可能在表单生成器中创建 div 元素。
如果您可以使用 Twig,那么您可以在 dividually 中呈现字段的三个部分,在具有您的自定义 class
的 div 中
<div class=wrap-title"">
{{ form_label(form.title) }}
{{ form_errors(form.title) }}
{{ form_widget(form.title) }}
</div>
<div class=wrap-price"">
{{ form_label(form.price) }}
{{ form_errors(form.price) }}
{{ form_widget(form.price) }}
</div>
使用 Symfony 3 并像这样构建一个表单域:
$builder
->add('tittle')
->add('price');
结果类似于:
<div>
<label ...></label>
<input ...>
</div>
我希望结果在包装 div
中包含自定义 css classes,例如:
<div class='wrap-title'>
<label ...></label>
<input ...>
</div>
<div class='wrap-price'>
<label ...></label>
<input ...>
</div>
尝试按照描述的方式做 here 并没有提供一种方法来将 class 添加到包装 div
中,只是其中的东西。
我不想使用 bootstrap 主题。我真的需要在那里添加一些我自己的东西作为 class。这可能吗?
希望这个回答能对您有所帮助:
我认为不可能在表单生成器中创建 div 元素。
如果您可以使用 Twig,那么您可以在 dividually 中呈现字段的三个部分,在具有您的自定义 class
的 div 中<div class=wrap-title"">
{{ form_label(form.title) }}
{{ form_errors(form.title) }}
{{ form_widget(form.title) }}
</div>
<div class=wrap-price"">
{{ form_label(form.price) }}
{{ form_errors(form.price) }}
{{ form_widget(form.price) }}
</div>