title: Symfony2 Twig and boolean false
body: <p>I try to generate URL with Twig in my Symfony2 project.
  My URL take Boolean as parameters, when I put True in the twig it's work but when I put false an error is throw.</p>
  
  <blockquote>
    <p>An exception has been thrown during the rendering of a template
    ("Parameter "boolean" for route "route_1" must match "[^/]++" (""
    given).</p>
  </blockquote>
  
  <pre><code>{{ path('route_1', {'id': item.id, 'boolean': false }) }}
  </code></pre>
  
  <p>I haven't any requirement on this parameter.</p>
  
  <pre><code>    /**
       * @Route("route1-{id}/boolean{boolean}", requirements={"id" = "\d+"}, name="route_1")
       */
      public function Route1Action($id, $boolean, Request $request) {
           //Some stuff
      }
  </code></pre>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>So, use Boolean in URL is bad. I put number and php convert automatically in boolean. 0 is false and all other numbers is true.</p>
  
  <pre><code>&lt;?php
  var_dump((bool) "");        // bool(false)
  var_dump((bool) 1);         // bool(true)
  var_dump((bool) -2);        // bool(true)
  var_dump((bool) "foo");     // bool(true)
  var_dump((bool) 2.3e5);     // bool(true)
  var_dump((bool) array(12)); // bool(true)
  var_dump((bool) array());   // bool(false)
  var_dump((bool) "false");   // bool(true)
  ?&gt;
  </code></pre>
  
  <p><a href="http://php.net/manual/en/language.types.boolean.php" rel="nofollow">http://php.net/manual/en/language.types.boolean.php</a></p>
  
  <p>With this code it's work :</p>
  
  <p>Action :</p>
  
  <pre><code>/**
   * @Route("route1-{id}/boolean{boolean}", requirements={"id" = "\d+", "boolean" = "\d+"}, name="route_1")
   */
  public function Route1Action($id, $boolean, Request $request) {
       //Some stuff
  }
  </code></pre>
  
  <p>The url to generate :</p>
  
  <pre><code>{{ path('route_1', {'id': item.id, 'boolean': 0 }) }} //To send false
  {{ path('route_1', {'id': item.id, 'boolean': 1 }) }} //To send true (1 or any other numbers)
  </code></pre>
  
  <p><strong>Thanks for your help. :)</strong></p>