Symfony crud generator by default create two forms, for create and update. I want to create a twig template form.html.twig with only one form for both actions, I remember symfony 1.x I did this:
<form action="<?php echo url_for('blog/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
If object don’t have
idthis is a new object.You can check if it is a new object in template like this:
Twig: