Symfony2->树枝->表格->字段->设置渲染= true [英] Symfony2 -> Twig -> Form -> Field -> Set rendered = true

查看:71
本文介绍了Symfony2->树枝->表格->字段->设置渲染= true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题.

我有一个带有字段的表单,例如:

$builder
    ->add('x')
    ->add('y')
    ->add('z')
;

在我的树枝文件中,我使用了多个块,并且我想停止渲染字段... 我查看了b.html.twig文件!

In my twig files i used multiple blocks and i want to stop render fields... I view the b.html.twig file!

a.html.twig

{% block body %}
    {% block form %}
        {{ form_widget(form) }}
    {% endblock form %}
{% endblock body %}

b.html.twig

{% block form %}
    {{ form.x.set('rendered', true) | default() }}
    {{ parent() }}
{% endblock form %}

如果我删除"default()",则会收到错误消息,表明该对象无法转换为字符串. 实际上,该表单会呈现所有字段...包括x字段.但是他们不应该渲染x字段...

If i remove the "default()" i get the error, that the object cant be converted to a string. And actually the form renders all fields... Inclusive the x field. But they shouldnt render the x field...

提前谢谢!

推荐答案

我在这里错过了这个问题吗?如果您想将一个字段设置为呈现状态,即使不是,那么简单的调用是:

Am I missing the question here? If you want to set a field as rendered even though it is not the simple call is:

{% do form.x.setRendered %}

如果我误解了,我道歉.

If I misunderstood, my apologies.

这篇关于Symfony2->树枝->表格->字段->设置渲染= true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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