Embed a Collection of Forms Symfony 6

31 Views Asked by At

Variable $chart does not exist inside Prototype of collection the template block _task_tags_entry_row.

Here are the Controller

public function edit(Request $request): Response {
    // .... ///
    $chartBuilder = new ChartBuilderInterface();
    
    // set the data for the chart
    $chartBuilder->setData([
        'labels' => ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
        'datasets' => [
            ['label' => 'Cookies eaten ', 'data' => [2, 10, 5, 18, 20, 30, 45]],
            ['label' => 'Km walked ‍♀️', 'data' => [10, 15, 4, 3, 25, 41, 25]],
        ],
    ]);

    // pass the chart builder instance to the render function
    return $this->render('example.html.twig', [
        'form' => $form,
        'task' => $task,
        'chart' => $chartBuilder,
    ]);
}

And here are the template

// here are the task form ...

                </div>
                {{ form_row(form.task) }}
                {{ form_row(form.tags) }}
                {{ render_chart(chart) }} <<====  the chart is displayed here properly 
            </div>
        </div>
    </section>
    {{ form_end(form) }}
{% endblock %}

{% form_theme form _self %}
{% block _task_tags_entry_row %}

    {{ render_chart(chart) }} <<======= But i want to display the chart Here, this give me an error Variable "chart" does not exist.
    {{ form_row(form.tag) }}

{% endblock %}

I have a collection of tags related to task, and I am creating a chart in the controller that I want to display inside the embedded form {{ render_chart(chart) }}, but I do not have access to chart variable.

PS: the chart is displayed within the task form.

how can i access to chart inside the collection form ?

0

There are 0 best solutions below