Php 覆盖Symfony2中的引导表单模板
Symfony 2.8 我试图覆盖表单的一些引导主题块。 对主题“bootstrap\u 3\u horizontal\u layout.html.twig”中的块“form\u label\u class”特别感兴趣: 我创建了文件my_form.html.twig,并从“bootstrap_3_horizontal_layout.html.twig”继承了它: 在form类中还添加了“宽度测试”的定义:Php 覆盖Symfony2中的引导表单模板,php,forms,twitter-bootstrap,symfony,Php,Forms,Twitter Bootstrap,Symfony,Symfony 2.8 我试图覆盖表单的一些引导主题块。 对主题“bootstrap\u 3\u horizontal\u layout.html.twig”中的块“form\u label\u class”特别感兴趣: 我创建了文件my_form.html.twig,并从“bootstrap_3_horizontal_layout.html.twig”继承了它: 在form类中还添加了“宽度测试”的定义: .... public function buildView(FormView $vi
....
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['width_test'] = $options['width_test'];
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('width_test', 3);
}
问题:由于出现错误:
表单/my\u form.html.twig中不存在变量“width\u test”
重要的是,“宽度测试”不仅在块“form\u label\u class”中定义,而且在块“form\u start”中显示它也没有问题
{% use "bootstrap_3_horizontal_layout.html.twig" %}
{% block form_start -%}
...
{% endblock form_start -%}
{% block form_label_class -%}
{{ width_test }}
{%- endblock form_label_class %}
....
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['width_test'] = $options['width_test'];
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('width_test', 3);
}