title: How do you check if an object exists in the Twig templating engine in Symfony2?
body: <p>I have a multidimensional array where some objects exist and others don't. I keep getting a</p>
  
  <p><strong>Method "code" for object "stdClass" does not exist in...</strong>?</p>
  
  <p>The code I am using in my template is:</p>
  
  <pre><code>{% for item in items %}
      &lt;p&gt;{% if item.product.code %}{{ item.product.code }}{% endif %}&lt;/p&gt;
  {% endfor %}
  </code></pre>
  
  <p>Some products do not have this code and unfortunately this data structure is provided via a feed, so I cannot change it.</p>
  
  <p>When I looked at the Twig documentation I interpreted that if an object or method was not there it would just return null?</p>