title: Redirect back with Symfony and twig
body: <p>In my Symfony project I have two views. Details view of specific entity and a button to lead me to a new view with with some other data by date param.</p>
  <p>The problem with the code I have is of generating 'Return to previous' page button from second method back to first..</p>
  <p>Code:</p>
  <pre><code>/**
   * @Route(&quot;/details/{id}&quot;, name=&quot;first_method&quot;)
   */
  public function firstMethod(Detail $id)
  {
      $workspace = $this-&gt;entityManager
          -&gt;getRepository(Detail::class)
          -&gt;find($id);
  
      $build['detail'] = $detail;
  
  $form = $this-&gt;createFormBuilder()
          -&gt;add('date', DateTimeType::class, [
              'data' =&gt; new \DateTime(),
              'widget' =&gt; 'single_text'
          ])
          -&gt;add(
              'save',
              SubmitType::class,
              [
                  'attr' =&gt; ['class' =&gt; 'btn-submit']
              ]
          )
          -&gt;getForm();
  
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
          $data = $form-&gt;getData();
          $date = $data['date']
  
          return $this-&gt;redirectToRoute('second_method', [
              'date' =&gt; $date
          ]);
      }
  
      return $this-&gt;render('first-method.html.twig', [
            'detail' =&gt; $detail,
          ]);
  }
  </code></pre>
  <p>And there is that 'second' method:</p>
  <pre><code> /**
   * @Route(&quot;/second-method/{date}&quot;, name=&quot;second_method&quot;)
   */
  public function secondMethod($date)
  {
      return $this-&gt;render('second-method.html.twig', [
          'someData' =&gt; $someData,
          'date' =&gt; $date,
      ]);
  }
  </code></pre>
  <p>I have a button on the second_method twig view which needs to return me back to method_one page.</p>
  <p>How can accomplish that as the parameter $id is probably needed in second method but can not find a way to provide it. Maybe there is some other way? Can someone help?</p>
  <p>I think in this first way it shoud me like:</p>
  <pre><code>{{ path('first_method', {'detailId':detail.id}) }}
  </code></pre>