Show forms in twig with symfony

0

I'm trying to make a comment system in symfony but at the moment of rendering the form in a for as follows

twig code:

{% for publicacion in publicaciones %}
    {{form(form}}
{% endfor %}

the form is shown only once and is not shown for each publication that is made

    
asked by Mike Gonzalez 15.07.2018 в 02:25
source

1 answer

0

Instead of creating just one form on your controller, create an array with a form for each publication:

$formArray=[]
foreach($publicaciones as $publicacion)
{ 
    $form = $this->createFormBuilder($publicacion);
    $formArray[$publicacion]=$form;
}

In this way you have an array that uses the publication as an index and the form as a value. then in the view:

{% for publicacion in publicaciones %}
    {{form(formArray[publicaion]}}
{% endfor %}
    
answered by 16.11.2018 в 16:12