【发布时间】:2016-03-12 12:36:39
【问题描述】:
我正在使用带有 Symfony 表单的 Silex 微框架。在树枝模板中,我使用以下方法生成该字段:
...
{{ form_widget(form.transport_selection) }}
...
如何覆盖这个 symfony twig 表单模板,以便为 Silex 中的每个集合(输入字段和标签)生成换行。
这是我的树枝注册:
use Silex\Provider\FormServiceProvider;
use Symfony\Component\Translation\Loader\YamlFileLoader;
use Symfony\Component\Validator\Constraints as Assert;
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => [
__DIR__.'/App/View',
]
));
如何为每个单选选项用 div 包装单选按钮和标签?
输出:
<div id="form_transport_selection">
<input type="radio" id="form_transport_selection_0" name="form[transport_selection]" required="required" value="country" checked="checked">
<label for="form_transport_selection_0" class="required">country</label>
<input type="radio" id="form_transport_selection_1" name="form[transport_selection]" required="required" value="abroad">
<label for="form_transport_selection_1" class="required">abroad</label>
</div>
预期输出:
<div id="form_transport_selection">
<div class="radio1">
<input type="radio" id="form_transport_selection_0" name="form[transport_selection]" required="required" value="country" checked="checked">
<label for="form_transport_selection_0" class="required">country</label>
</div>
<div class="radio2">
<input type="radio" id="form_transport_selection_1" name="form[transport_selection]" required="required" value="abroad">
<label for="form_transport_selection_1" class="required">abroad</label>
</div>
</div>
谢谢
【问题讨论】:
标签: twig symfony-forms silex