title: ZF2 custom methods in view model available to specific template
body: <p>Can't find any reasonable answers anywhere on this.</p>
  
  <p>In a controller, you return an instance of <code>ViewModel</code> which can have child ViewModel's included. That's fine, i get it, but these children blocks need variables also, which you can set right there in the same controller action. But how do you avoid 11 page long controller actions exactly?</p>
  
  <p>In Magento for example, view scripts derive from "blocks" which are classes with specific methods to alter the view, so you can simply get the child html and it will handle itself independently using its own methods.</p>
  
  <p>Practical (template method):</p>
  
  <pre><code>&lt;?php echo $this-&gt;getSidebar(); ?&gt;
  </code></pre>
  
  <p>Impractical (ZF2 controller):</p>
  
  <pre><code>$leftSidebar = new ViewModel(...
  $leftSidebarPostsWidget = new ViewModel(...
  $leftSidebar-&gt;addChild($leftSidebarPostsWidget);
  $view = new ViewModel();
  $view-&gt;addChild($leftSidebar);    
  
  return $view;
  </code></pre>
  
  <p>I looked into view helpers but those seem to be available to all view scripts which is unnecessary.</p>
  
  <p>Is there some way to associate custom render classes with specific templates?</p>
  
  <p>I could just create block classes that extend ViewModel, but i'm afraid i'm just missing something useful in Zend Framework 2.</p>