Symfony 2.8
我试图覆盖表格的一些引导主题块。 特别感兴趣的是" form_label_class"在主题" bootstrap_3_horizontal_layout.html.twig":
{% block form_label_class -%}
col-sm-2
{%- endblock form_label_class %}
我创建了文件my_form.html.twig并从" bootstrap_3_horizontal_layout.html.twig"继承了它:
{% use "bootstrap_3_horizontal_layout.html.twig" %}
{% block form_start -%}
...
{% endblock form_start -%}
{% block form_label_class -%}
{{ width_test }}
{%- endblock form_label_class %}
还添加了" width_test"的定义。在表单类中:
....
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);
}
问题:由于收到错误:
变量" width_test"表单/ my_form.html.twig
中不存在
重要的是," width_test"不仅仅在块" form_label_class"中定义,但没有问题显示它,例如在块" form_start"