Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 覆盖Symfony2中的引导表单模板_Php_Forms_Twitter Bootstrap_Symfony - Fatal编程技术网

Php 覆盖Symfony2中的引导表单模板

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

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 $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);
}