简体   繁体   English

如何在Symfony中自定义引导程序水平表单主题/模板?

[英]How to customise bootstrap horizontal form theme/template in Symfony?

I am working on an application built using Symfony 3. I am using the ' bootstrap_3_horizontal_layout.html.twig ' form theme that came with the framework. 我正在使用Symfony 3构建的应用程序。我正在使用框架随附的“ bootstrap_3_horizo​​ntal_layout.html.twig ”表单主题。

I have imported it successfully. 我已经成功导入了。

I tried to change the default column sizes; 我试图更改默认的列大小; http://pastebin.com/7QvEQyVi but doesn't seem to have any effect. http://pastebin.com/7QvEQyVi,但似乎没有任何作用。

The default sizes are 2 and 10 for the labels and input columns respectively. 标签和输入列的默认大小分别为2和10。 How can I override these values? 如何覆盖这些值?

Appreciate any guidance 感谢任何指导

You can override it in your own template 您可以在自己的模板中覆盖它

app/config/config.yml app / config / config.yml

# Twig Configuration
twig:
    form_themes:
        - "form/fields.html.twig"

app/Resources/views/form/fields.html.twig app / Resources / views / form / fields.html.twig

{% use 'bootstrap_3_horizontal_layout.html.twig' %}

{% block form_label_class -%}
col-sm-3
{%- endblock form_label_class %}

{% block form_group_class -%}
col-sm-9
{%- endblock form_group_class %}

I got it working by placing the modified block in a separate file as per @jkuchravic's answer; 通过按照@jkuchravic的回答将修改后的块放置在单独的文件中,可以使它起作用。

app/Resources/views/form/fields.html.twig app / Resources / views / form / fields.html.twig

{% use 'bootstrap_3_horizontal_layout.html.twig' %}

{% block form_label_class -%}
col-sm-3
{%- endblock form_label_class %}

{% block form_group_class -%}
col-sm-9
{%- endblock form_group_class %}

I didn't want to make the change application-wide so just applied the modified template to that particular form using the following line: 我不想在整个应用程序范围内进行更改,因此只需使用以下行将修改后的模板应用于该特定表单:

{% form_theme form with ['bootstrap_3_horizontal_layout.html.twig','form/fields.html.twig'] %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM