symfonytwigsymfony-formssymfony2

Symfony2 -> Twig -> Form -> Field -> Set rendered = true


i have a simple problem.

I have a form with a field for example:

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

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 %}

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...


Solution

  • 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.