Symfony2 - 多种形式的主题 [英] Symfony2 - theme for multiple forms

查看:162
本文介绍了Symfony2 - 多种形式的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在同一页面上为两个(或更多)表单使用不同的主题。
我有2种形式,我想用第一种形式的主题X和第二种形式的主题Y。

解决方案



您应该尝试:

pre $ {%form_theme form'ThemeX.html.twig'%}
{{form(formX)}}

{%form_theme form'ThemeY .html.twig'%}
{{form(formY)}}

不起作用(即第二种形式的主题声明不会覆盖第一种形式),只需为第二种形式使用单独的模板并使用include将其插入到父模板中即可。



尝试[ HTTP:// symfony的.com / doc / current / cookbook / form / form_customization.html#child-forms](这个页面)获取更多信息


Is there way to use diffrent themes for two (or more) forms on the same page. I've 2 forms and I'd like to use theme "X" for first form and theme "Y" for second form.

解决方案

You need to declare your theme before displaying your form.

You should try :

{% form_theme form 'ThemeX.html.twig' %}
    {{ form(formX) }}

{% form_theme form 'ThemeY.html.twig' %}
    {{ form(formY) }}

If that doesn't work (ie. second form theme declaration doesn't overwrite the first one), just use a separate template for your second form and insert it in your parent template using an include.

Try [http://symfony.com/doc/current/cookbook/form/form_customization.html#child-forms](this page) of symfony doc for more information

这篇关于Symfony2 - 多种形式的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆