title: Call PHP function from Twig template
body: <p>I have a function in my controller that returns array of entities so in my twig template I do this to iterate over elements:</p>
  
  <pre><code>{% for groupName, entity in items %}
      &lt;ul&gt;
          &lt;ul&gt;
              {% for element in entity %}
                  &lt;li&gt;{{ element.getLabel }}&lt;/li&gt;
                  &lt;li&gt;&lt;input type="text" name="detail[{{ element.getId }}]" id="pd_{{ element.getId }}" /&gt;&lt;input type="text" name="price[{{ element.getId }}]" id="pd_price_{{ element.getId }}" /&gt;&lt;input type="text" name="stock[{{ element.getId }}]" id="pd_stock_{{ element.getId }}" /&gt;&lt;/li&gt;
              {% endfor %}
          &lt;/ul&gt;
      &lt;/ul&gt;
  {% endfor %}
  </code></pre>
  
  <p>In my controller I have also this PHP function:</p>
  
  <pre><code>private function DetailCombination($arr, $level, &amp;$result, $curr = array()) {
      for ($i = 0; $i &lt; count($arr); $i++) {
          $new = array_merge($curr, array($arr[$i]));
          if ($level == 1) {
              sort($new);
              if (!in_array($new, $result)) {
                  $result[] = $new;
              }
          } else {
              combinations($arr, $level - 1, $result, $new);
          }
      }
  }
  </code></pre>
  
  <p>I can call it in this way:</p>
  
  <pre><code>for ($i = 0; $i &lt; count($arr); $i++) {
      $this-&gt;DetailCombination($arr, $i + 1, $result);
  }
  
  // TEST
  foreach ($result as $arr) {
      echo join(" ", $arr) . '&lt;br&gt;';
  }
  </code></pre>
  
  <p>It's possible access to the PHP function from Twig template in order to get all the possible combinations of elements in entity? How?</p>
  
  <p>** UPDATE **</p>
  
  <p>This is the function that returns entities processed after by Twig Template:</p>
  
  <pre><code>private function getVariations($category_id) {
      $items = array();
  
      $em = $this-&gt;getDoctrine()-&gt;getManager();
      $entityCategory = $em-&gt;getRepository('CategoryBundle:Category')-&gt;find($category_id);
  
      foreach ($entityCategory-&gt;getProductDetails() as $entity) {
          if ($entity-&gt;getToProduct() == 1) {
              foreach ($entity-&gt;getDetailGroup() as $group) {
                  if (!array_key_exists($group-&gt;getName(), $items)) {
                      $items [$group-&gt;getName()] = array();
                  }
  
                  $items [$group-&gt;getName()] [] = $entity;
              }
          } 
      }
  
      return $items;
  } 
  </code></pre>