I've got this error and do know why is this happening. It was working two days ago:
An exception has been thrown during the rendering of a template ("Field "app_config" has already been rendered, save the result of previous render call to a variable and output that instead.").
Thats the view:
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn btn-outline-success">{{ button_label|default('app.save'|trans) }}</button>
{{ form_end(form) }}
And the controller:
$appConfig = new AppConfig();
$form = $this->createForm(AppConfigType::class, $appConfig);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$appConfigRepository->add($appConfig, true);
return $this->redirectToRoute('backend_settings_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('backend/crud/backend_settings/new.html.twig', [
'app_config' => $appConfig,
'form' => $form,
]);
The error cames from FromRenderer.php
/**
* {@inheritdoc}
*/
public function searchAndRenderBlock(FormView $view, string $blockNameSuffix, array $variables = []): string
{
$renderOnlyOnce = 'row' === $blockNameSuffix || 'widget' === $blockNameSuffix;
if ($renderOnlyOnce && $view->isRendered()) {
// This is not allowed, because it would result in rendering same IDs multiple times, which is not valid.
throw new BadMethodCallException(sprintf('Field "%s" has already been rendered, save the result of previous render call to a variable and output that instead.', $view->vars['name']));
}
``