title: ZF2 Seperate HTML from Recursive PHP function(s)
body: <p>I'm trying to seperate the HTML elements from the PHP code within Zend Framework 2, but I have no clue on how to solve this problem/seperate. Im currently echo'ing those HTML elements, which does the job. But there must be a way to seperate the HTML from PHP, instead of echo'ing the HTML elements.</p>
  
  <p>At the moment I made a viewhelper which helps me to let me generate this treeMap for other modules aswell, since those will also use this feature, aslong as this helper is given with a treeMap. The categoryTreeMap contains a treemap of category (Doctrine 2 ORM) objects.</p>
  
  <p>This is what I've got so far:</p>
  
  <pre><code>namespace Application\View\Helper;
  
  use Zend\View\Helper\AbstractHelper;
  
  class CategoryTreeMapHelper extends AbstractHelper
  {
      public function __invoke($categoryTreeMap)
      {
          echo "&lt;ol class=\"sortable\"&gt;";
          foreach ($categoryTreeMap as $category) {
              $this-&gt;showCategories($category);
          }
          echo "&lt;/ol&gt;";
      }
  
      public function showCategories($category)
      {
          echo "&lt;li&gt;&lt;div&gt;" . $category-&gt;name . "&lt;/div&gt;";
          if (isset($category-&gt;childs)) {
              echo "&lt;ol&gt;";
              foreach ($category-&gt;childs as $child_category) {
                  $this-&gt;showCategories($child_category);
              }
              echo "&lt;/ol&gt;";
          }
          echo "&lt;/li&gt;";
      }
  }
  </code></pre>
  
  <p>Any suggestions on how to solve this, by seperating the HTML from the PHP echo's.</p>