title: Can you conditionally pass a variable to Twig
body: <p>So I am building a component and want the ability to bind a value to it or leave it blank. Ideally I would like to do this without the if statement maybe with filters or some type of ternary operator. So can I ever use this without explicitly passing a <code>date</code></p>
  
  <pre><code>{% if date is not defined %}
      &lt;input type='text' name="date" value="" class="form-control date-picker" /&gt;
      &lt;input type='hidden' name="timezone" class="timezone" /&gt;
  {% else %}
      &lt;input type='text' name="{{date.name | default("date")}}" value="{{ date.value | default("")}}" class="form-control date-picker" /&gt;
      &lt;input type='hidden' name="timezone" class="timezone" /&gt;
  {% endif %}
  </code></pre>
  
  <p>This is the ugly broken code I ended up with after trying multiple things. </p>
  
  <p>I cannot load the component without giving it a value for <code>date</code></p>
  
  <pre><code>$date = '';
  return $this-&gt;render('ComponentBundle:Default:datepicker.html.twig',array(
              'date' =&gt; $date,
         ));
  </code></pre>
  
  <p>The error i get when i don't pass <code>date</code> to the view is </p>
  
  <pre><code>Variable "date" does not exist in ComponentBundle:Default:datepicker.html.twig at line 10
  </code></pre>